onunload call when reloading page quickly

N

nic den

hello,

I'm calling a function to delete a cookie when a page is left.
The problem is when I quickly push the reload button of my browser. The
browser doesn't understand what's happening and don't call my exit function,
maybe not enough time ?

How could I solve this problem in order to be sure that finally the cookie
is deleted ?

thanks a lot

nicolas


ps. here's my code:


function getCookie(name) {
var dc = window.document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else
begin += 2;
var end = window.document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
if (getCookie(name)) {
var cookieVal = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";

window.document.cookie = cookieVal;
window.top.document.cookie = cookieVal;

window.ff_top.document.cookie = cookieVal;
window.ff_left.document.cookie = cookieVal;
window.ff_ct.document.cookie = cookieVal;
}
}

function exitPage() {
alert(window.document.cookie);
deleteCookie("moncookiedetest","/","");

}
window.onunload=exitPage;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top