Home >Web Front-end >JS Tutorial >js sets cookie expiration current time minus one second is equivalent to immediate expiration_javascript skills
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=/; indicates that the cookie is stored in the browser root directory
The above method causes the four cookies appCode, roleID, parentMenuID, and currentMenuName to become invalid