Possible Duplicate:
Clearing all cookies with javascript
I would like to have a checkbox assigned to activate and wipe out all cookies previously stored in my forms in one go. How would I do that with jquery cookie plugin? I can't seem to find examples in Klaus site and here.
Any hint would be very much appreciated.
Thanks
The accepted answer in this question should accomplish what you're after:
var cookies = document.cookie.split(";");
for(var i=0; i < cookies.length; i++) {
var equals = cookies[i].indexOf("=");
var name = equals > -1 ? cookies[i].substr(0, equals) : cookies[i];
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
(code is expanded for clarity from the linked answer, no need to reinvent the wheel here)
There's no need for a plugin in all cases, sometimes a simple JavaScript snippet will do...jQuery really doesn't help at all here
You do not need to use jquery for that, only pure javascript:
function setCookie(name, value, seconds) {
if (typeof(seconds) != 'undefined') {
var date = new Date();
date.setTime(date.getTime() + (seconds*1000));
var expires = "; expires=" + date.toGMTString();
}
else {
var expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
And call with setCookie( cookieName, null, -1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With