Revolution X

Coding Community => Coding Snippets => Topic started by: Agent Moose on April 21, 2009, 04:59:44 pm



Title: Alert on Logout
Post by: Agent Moose on April 21, 2009, 04:59:44 pm
Footers:
Code:
<script type="text/javascript">
var Leave = "YOUR TEXT";

var name = document.getElementsByTagName("span");
//Created by Agent Moose (revolutionx.smfforfree.com)
for(v=0;v<name.length;v++){
if(name[v].innerHTML.match(/Hello <b>(.*)<\/b>/i)){
var username = RegExp.$1;
};};
var Logout = document.links;
for(c=0;c<Logout.length;c++){
if(Logout[c].href.match(/action=logout/i) && Logout[c].parentNode.className == "maintab_back"){
Logout[c].onclick = function(){ if(confirm(Leave) == true) { window.location.href = smf_scripturl + "?action=logout"; } else { return false; } };
};};
if(Leave.match(/{user}/i)) Leave = Leave.replace(/{user}/i,username);
</script>
Original Request: http://revolutionx.smfforfree3.com/index.php/topic,429.0.html (http://revolutionx.smfforfree3.com/index.php/topic,429.0.html)

When this code is added to your forum, a pop-up box will appear when you click the "Logout" tab.

YOUR TEXT = The text the message will show.
If you want to show the user's name in the message, put {user}.

Enjoy :)


Title: Re: Alert on Logout
Post by: code learner on April 21, 2009, 08:01:45 pm
thanks really needed this one thank you moose love it  O0


Title: Re: Alert on Logout
Post by: Andrew on April 22, 2009, 06:44:11 pm
Love it moose! using it now.


Title: Re: Alert on Logout
Post by: Vitality on April 22, 2009, 08:04:44 pm
Good to see you've been using classic JS. I have to break out of my jQuery phase right now  ;D
Nice work Moose


Title: Re: Alert on Logout
Post by: Agent Moose on April 23, 2009, 04:21:37 pm
Glad you all like it :)

Good to see you've been using classic JS. I have to break out of my jQuery phase right now  ;D
Nice work Moose

I know how it is with jquery man :P  I've been using classic JS because it looks better, and it looks more profesional :P

Mind you, there are still some things I use jquery on, mainly if I get lazy, or if it is a code I don't know how to do without it :P


Title: Re: Alert on Logout
Post by: Andrew on April 24, 2009, 05:37:13 pm
Theres only one problem with this, When I tried to X out of the alert that comes up, it logs my out anyway  :o


Title: Re: Alert on Logout
Post by: Agent Moose on April 25, 2009, 07:09:28 am
I shall fix that later.  I guess I should of used a confirm box :P


Title: Re: Alert on Logout
Post by: Agent Moose on April 27, 2009, 06:42:52 am
I hadn't tested this code yet, but it should work.  When someone tests it, I will edit the first post:
Code:
<script type="text/javascript">
var Leave = "YOUR TEXT";

var name = document.getElementsByTagName("span");
for(v=0;v<name.length;v++){
if(name[v].innerHTML.match(/Hello <b>(.*)<\/b>/i)){
var username = RegExp.$1;
};};
var Logout = document.links;
for(c=0;c<Logout.length;c++){
if(Logout[c].href.match(/action=logout/i) && Logout[c].parentNode.className == "maintab_back"){
Logout[c].onclick = function(){ if(confirm(Leave) == true) window.location.href = smf_scripturl + "?action=logout"; };
};};
if(Leave.match(/{user}/i)) Leave = Leave.replace(/{user}/i,username);
</script>


Title: Re: Alert on Logout
Post by: Andrew on April 30, 2009, 07:58:11 am
I just tried that one, it has the "OK" and "Cancel" buttons, but they do the same thing as the last one. Even if I would click "Cancel" it would log me out.


Title: Re: Alert on Logout
Post by: Celebrus on April 30, 2009, 08:55:16 am
Try this:
Code:
<script type="text/javascript">
var Leave = "YOUR TEXT";

var name = document.getElementsByTagName("span");
for(v=0;v<name.length;v++){
if(name[v].innerHTML.match(/Hello <b>(.*)<\/b>/i)){
var username = RegExp.$1;
};};
var Logout = document.links;
for(c=0;c<Logout.length;c++){
if(Logout[c].href.match(/action=logout/i) && Logout[c].parentNode.className == "maintab_back"){
Logout[c].onclick = function(){ if(confirm(Leave) == true) { window.location.href = smf_scripturl + "?action=logout"; } else { return false; } };
};};
if(Leave.match(/{user}/i)) Leave = Leave.replace(/{user}/i,username);
</script>

I basically just got what Agent wrote to return false.


Title: Re: Alert on Logout
Post by: Andrew on April 30, 2009, 09:35:59 am
Try this:
Code:
<script type="text/javascript">
var Leave = "YOUR TEXT";

var name = document.getElementsByTagName("span");
for(v=0;v<name.length;v++){
if(name[v].innerHTML.match(/Hello <b>(.*)<\/b>/i)){
var username = RegExp.$1;
};};
var Logout = document.links;
for(c=0;c<Logout.length;c++){
if(Logout[c].href.match(/action=logout/i) && Logout[c].parentNode.className == "maintab_back"){
Logout[c].onclick = function(){ if(confirm(Leave) == true) { window.location.href = smf_scripturl + "?action=logout"; } else { return false; } };
};};
if(Leave.match(/{user}/i)) Leave = Leave.replace(/{user}/i,username);
</script>

I basically just got what Agent wrote to return false.

Thanks Cele! It worked right :)



Title: Re: Alert on Logout
Post by: Mojobojo82 on June 17, 2009, 05:48:41 am
Thanks Moose, Works nice and soothe :)


Title: Re: Alert on Logout
Post by: Santadomin on August 15, 2009, 10:23:33 pm
Nice code, i'm using it right now  O0