开发者

Delete cookies via JavaScript [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Javascript cookie delete

Please let me know how to delete specific cookie (I have the name of the cookie its enough..).

I really dont have an idea (I dont know JS well...) and when I searched in Google I didn't find a good solution.

Thank you.

EDIT: If I can't delete the coo开发者_高级运维kie - let me know how to change the value to "" (empty..), its ok too.


Stolen from here:

function del_cookie(name) {
   document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
} 

This sets the cookie value to nothing (name + '=;) and sets the expiration time to the past (expiring it immediately).


Try this (adapted from here):

function DeleteCookie(name, path, domain) 
{
    path = (path ? ";path=" + path : "");
    domain = (domain ? ";domain=" + domain : "");
    var expiration = "Thu, 01-Jan-1970 00:00:01 GMT";

    document.cookie = name + "=" + path + domain + ";expires=" + expiration;
}

Essentially, you delete cookies by setting their expiration date to a date guaranteed to be in the past.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜