Clear Cookie Through JavaScript in iPod/iPad Safari

In iPod/iPad safari if you excess your main site made in .net and want to clear the cookies through JavaScript as user goes to another page, iPod/iPad doesn't support "onbeforeunload" event so what you do?

Add the following on the aspx page in script tag:

 document.onclick = ClearCookiesOnClick; //this will run this function on every click.

Create the calling functions like this:

function ClearCookiesOnClick(e) {
   
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
       
var target = (e && e.target) || (event && event.srcElement);
// Find the ID of the link for which you want to clear the cookies
        if (target.id == 'IDOflink') {
            setCookie(
"CookieName", '', -2);
        }
    }
}

function
setCookie(c_name, value, expiredays) {
   
var exdate = new Date();

   
var expires = ((expiredays == null) ? "" : "; expires=" + exdate.toGMTString());
    document.cookie = c_name +
"=" + value + expires + "; path=/";
}

That's it; you are good to go.

Ebook Download
View all
Learn
View all