Is there anyway to edit the logout html to add an onclick function?
I would like to add this to ask my members are they sure they want to logout.
I would like to add this to ask my members are they sure they want to logout.
Rideem3 wrote:Yeah, here's a code that will ask them to confirm their log out
Go to Admin Panel -> Modules -> JavaScript Codes Management -> Create a new JavaScript:
Title: Logout
Check "In All the Pages"
Put this code:
- Code:
jQuery(document).ready(function() {
jQuery('a[href*="/login?logout"]').attr({
onclick: "logConfirm()",
id: "logout"
});
});
function logConfirm() {
var x = confirm("Are you sure you want to logout?");
if (x == true) {
return true;
}else{
jQuery(document).ready(function() {
jQuery('#logout').attr({
href: "#"
});
});
}
}
Rideem3 wrote:All I see on your forum is this:
http://www.mystreetlife.com/99372.js
You must remove:
- Code:
$(function(){document.post.post.value="Post"});
$(function() {
document.post.post.value="Post";
});
$(function() {
if (document.post) { document.post.post.value="Post"; }
});
$(function() {
if (document.post) { document.post.post.value="Post"; }
var x=document.getElementById('logout');
if (x) {
$(x.parentNode).click(function(e) {
if (!confirm("Are you sure you want to logout?")) { e.preventDefault(); }
});
}
});
LGforum wrote:Its because that script will crash on a page where a send button doesn't exist.
All you need to do is change it to this:
- Code:
$(function() {
if (document.post) { document.post.post.value="Post"; }
});
And here is the other code improved on AND with the first code included in it:
So this is the ONLY code you need for these two tasks.
- Code:
$(function() {
if (document.post) { document.post.post.value="Post"; }
var x=document.getElementById('logout');
if (x) {
$(x.parentNode).click(function(e) {
if (!confirm("Are you sure you want to logout?")) { e.preventDefault(); }
});
}
});
Sorry for improving your code Rideem3, I meant no offence, but only for educational purposes.
LGforum wrote:Change (x.parentNode) to just (x)