Home > Web Front-end > JS Tutorial > body text

js设置cookie过期及清除浏览器对应名称的cookie_javascript技巧

WBOY
Release: 2016-05-16 17:19:01
Original
980 people have browsed it
复制代码 代码如下:

function ClearCookie() {
var expires = new Date();
expires.setTime(expires.getTime() - 1000); //当前时间减去一秒,相当于立即过期(可以增减)
document.cookie = "appCode='222''';path=/;expires=" + expires.toGMTString() + ""; //expires是对应过期时间的设置,不设这个值,cookie默认在关闭浏览器时失效
document.cookie = "roleID='333''';path=/;expires=" + expires.toGMTString() + "";
document.cookie = "parentMenuID='000''';path=/;expires=" + expires.toGMTString() + "";
document.cookie = "currentMenuName='哈哈''';path=/;expires=" + expires.toGMTString() + "";
}

path=/;表示cookie存放的位置是浏览器根目录

上述方法导致appCode,roleID,parentMenuID,currentMenuName4个cookie失效
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!