0

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

3
Contributors
4
Replies
18
Views
4 Years
Discussion Span
Last Post by gahhon
0

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();
}
1
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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.