Home > Web Front-end > JS Tutorial > js sets cookie expiration and clears the cookie with the browser's corresponding name_javascript skills

js sets cookie expiration and clears the cookie with the browser's corresponding name_javascript skills

WBOY
Release: 2016-05-16 17:19:01
Original
1040 people have browsed it
Copy code The code is as follows:

function ClearCookie() {
var expires = new Date() ;
expires.setTime(expires.getTime() - 1000); //The current time minus one second is equivalent to immediate expiration (can be increased or decreased)
document.cookie = "appCode='222''' ;path=/;expires=" expires.toGMTString() ""; //expires is the setting corresponding to the expiration time. If this value is not set, the cookie will expire when the browser is closed by default
document.cookie = "roleID=' 333''';path=/;expires=" expires.toGMTString() "";
document.cookie = "parentMenuID='000''';path=/;expires=" expires.toGMTString() "" ;
document.cookie = "currentMenuName='haha''';path=/;expires=" expires.toGMTString() "";
}

path=/; means The location where cookies are stored is the browser root directory

The above method causes the four cookies appCode, roleID, parentMenuID, and currentMenuName to become invalid.
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