D
donpro-2003
Hi,
I have an session application where the user logs out via a simplt
logot link. The code to do this is:
<a id="logout" title="Log out" href="logout.php" onClick="return
confirm('Do you really want to log out?')">Logout</a>
So if the user answers YES to the confim, logot.php is run and the
user is logged ot. If the user answers NO, they remain on the page.
I removed the onClick() and tried to use DOM but I find that with my
code, the user gets logged ot regardless of whether they choose YES or
NO so obviosly, my code is incomplete. I present it below, if anyon
can help, I wodl appreiciate it.
HTML
-------
<a id="logout" title="Log out" href="logout.php">Logout</a>
JavaScript
========
function addEvent(elm, evType, fn, useCapture) {
if (elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
return true;
} else if (elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);
return r;
} else {
elm['on' + evType] = fn;
}
}
function handleClick(e) {
return confirm('Do you really want to log out?');
}
function addListeners() {
if (!document.getElementById) {
return;
}
var logout_link = document.getElementById('logout');
addEvent(logout_link, 'click', handleClick, false);
}
addEvent(window, 'load', addListeners, false);
I have an session application where the user logs out via a simplt
logot link. The code to do this is:
<a id="logout" title="Log out" href="logout.php" onClick="return
confirm('Do you really want to log out?')">Logout</a>
So if the user answers YES to the confim, logot.php is run and the
user is logged ot. If the user answers NO, they remain on the page.
I removed the onClick() and tried to use DOM but I find that with my
code, the user gets logged ot regardless of whether they choose YES or
NO so obviosly, my code is incomplete. I present it below, if anyon
can help, I wodl appreiciate it.
HTML
-------
<a id="logout" title="Log out" href="logout.php">Logout</a>
JavaScript
========
function addEvent(elm, evType, fn, useCapture) {
if (elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
return true;
} else if (elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);
return r;
} else {
elm['on' + evType] = fn;
}
}
function handleClick(e) {
return confirm('Do you really want to log out?');
}
function addListeners() {
if (!document.getElementById) {
return;
}
var logout_link = document.getElementById('logout');
addEvent(logout_link, 'click', handleClick, false);
}
addEvent(window, 'load', addListeners, false);