welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Saturday, April 21, 2012

Delete all the cookies when user closes the browser window in

This article we ll see about how to clear all cookies when user close the browser window..
This question everyone one rise in common forum site, How to clear cookies when user close browser window. The process and i found the way to clear the cookies using JavaScript.
Here i call the JavaScript in body event 'onbeforeunload'

In previous article i used this event show warning message to user before closing browser window. For your reference here i mention the link below..

Here i used same event to clear all cookies before user close the window. When i looking for  the code ,it’s very difficult  to clear the cookies generated by server side..
If you are generated cookies using JavaScript, then you can easily clear the cookies, but you created in server side, you have to follow the same method to delete the cookies. Here i share the method to delete the cookies..

JavaScript code:
function clrcook(e) {
        var evt = window.event ? event : e;
        if (evt.clientY < 0) {

            var thecookie = document.cookie.split(";")
            for (var i = 0; i < thecookie.length; i++) {
                var expires = new Date();
                expires.setUTCFullYear(expires.getUTCFullYear() - 1);
                document.cookie = thecookie[i] + '; expires=' + expires.toUTCString() + '; path=/';



So Here you have to call the script in body tag event..
<body onbeforeunload="clrcook(event)">

When window closing the even has been fired and delete all the cookies i.e. set the expiry date. 

I hope you like this article..
Post your valuable comments here……


Post a Comment