How to use this jQuery plugin to delete cookies?

First, to display the cookie, I used the electrictoolbox.com code .

Then I made a form to add a cookie:

<form class="cokies" method="post">
<input class="query" name="q" type="text" />
<input type="submit" name="save" value="saving">
<a>Delete Cookies</a>
</form>
$(document).ready(function(){
$('.cokies a').click(function(){
    $.cookie('q', null);
});

remember('[name=q]');

This feature is from komodomedia.com :

function remember( selector ){
    $(selector).each(function(){
        //if this item has been cookied, restore it
        var name = $(this).attr('name');
        if( $.cookie( name ) ){
            $(this).val( $.cookie(name) );
        }

        //assign a change function to the item to cookie it
        $(this).change(function(){
            $.cookie(name, $(this).val(), { path: '/', expires: 365 });
        });
    });
}

The problem is that I cannot decide how to delete the cookie.

+5
source share
4 answers

To delete a cookie, simply set it expires:to a negative integer value.

Example:

$.cookie(name, $(this).val(), { path: '/', expires: -5 });

+14
source

New versions of the Cookie plugin have appeared and provide the following convenient syntax:

$.removeCookie('q');
+7
source

JQuery cookie script . , script jquery.cookie.js:

jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
    options = options || {};
    if (value === null) {
        value = '';
        options.expires = -1;
        options.path = "/";

    }
 ....

cookie, .

+2

$.removeCookie("COOKIE_NAME",{domain:'.domain.com',path:'/'});

Check the path and domain of the cookie and make sure that you add them to the advanced settings using the plugin $.cookie.

+1
source

All Articles