April 10, 2012

Clear cookie via jquery?

Question by SOLDIER-OF-FORTUNE

I have a DNN installation but one of the portals is broken and the “logout” button doesnt seem to clear the cokoie. Is it possible to use jquery to clear a specific cookie? or a seperate ASP.NET page?

Answer by Starx

Sure, Using cookie plugin like this

$.cookie("name", null);

Update:

if($('a[href="webiste.co.uk/en-gb/admin.aspx"]').length) {
    $.cookie("name", null);
}

Update 2: Pure Js

function deleteCookie(name) {
    document.cookie = name+'="";-1; path=/';
}

var login = document.getElementById("loginlink");
login.onclick = function() {
  deleteCookie("name");
};

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!