As i doing research i know most of them are suggesting use
<body onbeforeunload="beforeUnload" onunload="unload">

But i trying to do some sample, is this can't work it.
Could you guys provide a simplest example to me ?
In fact, i gonna to delete the Cookies value whenever they are trying to close web tab or shifting to non-of-my designed web page.

Thanks for in advance

Recommended Answers

All 4 Replies

Hey,

Maybe try something like this:

window.onbeforeunload = function() {
    //Clear Your Cookies Here
    deleteCookie('YOUR COOKIE NAME HERE');
    return 'Your Cookies Have Been Cleared!';
}

function deleteCookie(c_name) {
    document.cookie = encodeURIComponent(c_name) + "=deleted; expires=" + new Date(0).toUTCString();
}

The cookie is still remain un-remove. :(

function deleteCookies() {
    document.cookie = "Username=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/";
}

Soluton solved because left out the path=/ at the end of the cookie sentence.
Thanks for helping me folks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.