tags:

views:

383

answers:

3

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

+2  A: 

The accepted answer in this question should accomplish what you're after, no need for a plugin in all cases, sometimes a simple javascript snippet will do.

Nick Craver
Been there before, but was too eager to stay in jquery :) So I guess the answer is no easy way to wipe out cookies with jquery? Gotta grab the closest hand I can get then. Thanks
swan
jQuery is just a bunch of javascript, don't think of them like you're delegating out to something different...it's all the same stuff. Wrapping some things in a plugin isn't needed a fair portion of the time, it's usually just equivalent to changing the namespace for what some plugins do.
Nick Craver
You didn't answer the actual question related to jquery, but the link did answer my need for now. Thanks
swan
+1  A: 

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);

Artem Barger
but he want to do this using jQuery.
Rakesh Juyal
Yes, I love to see jquery version if any please. But I am always listening to any possible solution. Thanks
swan
Listen you two, jQuery **is** Javascript. There is absolutely no reason to want it one way or the other, because they are the same. jQuery should not be used to do this.
Josh Stodola
A: 

jQuery doesn't offer builtin ways for this, so you'll need to grab a jQuery plugin if you really don't want to use "plain vanilla JavaScript" for this.

I've checked the available plugins and those two simple plugins looks to suit your requirements.

BalusC
I did use Cookie plugin to store cookies, but forgive me if I missed anything, I can't seem to find example to wipe out ALL cookies. Neither in CooQuery. Can you show me one? Thanks
swan
Ah, you're right. You could extend/rewrite/homegrow a plugin which has a `getCookies()` method which returns all cookies in an array, so that you can iterate over them all and run `delCookie(name)` on each. Or look for a plugin which does exactly that :)
BalusC