javascript 通过jquery清除cookie?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10087494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 08:39:06  来源:igfitidea点击:

Clear cookie via jquery?

javascriptjqueryasp.netcookies

提问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?

我安装了 DNN,但其中一个门户坏了,“注销”按钮似乎无法清除 cokoie。是否可以使用 jquery 清除特定的 cookie?或单独的 ASP.NET 页面?

回答by Starx

Sure, Using cookie pluginlike this

当然,像这样使用cookie 插件

$.cookie("name", null);

Update:

更新:

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


Update 2:Pure Js

更新 2:纯 Js

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

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