[英]Javascript document.cookie remove “name” and “value”
In my Javascript I have a cookie with several names and values: 在我的Javascript中,我有一个带有几个名称和值的cookie:
"Token=23432112233299; sessionuid=abce32343234"
From server when I download a file a Add a Cookie so the new document cookie will look: 从服务器下载文件时,从服务器上添加“ Cookie”,以便新的文档Cookie看起来如下:
"Token=23432112233299; sessionuid=abce32343234; fileDownload=true"
How can I remove the fileDownload
name and value from cookie
and update document.cookie? 如何从
cookie
删除fileDownload
名称和值并更新document.cookie?
UPDATE: 更新:
This is the code I have done so far but its not working: 这是我到目前为止完成的代码,但是没有用:
if (document.cookie.indexOf("fileDownload=true;") != -1) {
document.cookie = document.cookie.replace("fileDownload=true;", "");
} else {
document.cookie = document.cookie.replace("fileDownload=true", "");
}
Change the expires parameter to the elapsed date. 将expires参数更改为经过的日期。
document.cookie = 'fileDownload = ; document.cookie ='fileDownload =; expires=-1';
expires = -1';
var cookieData = "fileDownload=; path=/" +"; expires=" + new Date(0).toUTCString() + ";";
if (null) cookieData += " domain=null;";
document.cookie = cookieData;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.