Js sets the current cookie expiration time minus one second, which is equivalent to immediate expiration. The current cookie time

Source: Internet
Author: User
Tags set cookie

Js sets the current cookie expiration time minus one second, which is equivalent to immediate expiration. The current cookie time

Function ClearCookie () {var expires = new Date (); expires. setTime (expires. getTime ()-1000); // The current time minus one second, which is equivalent to immediate expiration (can be increased or decreased) document. cookie = "appCode = '000000'''; path =/; expires =" + expires. toGMTString () + ""; // expires indicates the expiration time. If this parameter is not set, the cookie expires when the browser is disabled by default. cookie = "roleID = '000000'; path =/; expires =" + expires. toGMTString () + ""; document. cookie = "parentMenuID = '000'''; path =/; expires =" + expires. toGMTString () + ""; document. cookie = "currentMenuName = 'haha '''; path =/; expires =" + expires. toGMTString () + "";}

Path =/; indicates that the cookie is stored in the browser root directory.

As a result, four cookies (appCode, roleID, parentMenuID, and currentmenuname) are invalid.


Set cookie expiration time in js

Function SetCookie (name, value ){
Var str = name + "=" + escape (value );
Var dd = new Date ();
Dd. setDate (dd. getDate () + 1); // get tomorrow
Var y = dd. getYear ();
Var m = dd. getMonth () + 1; // obtain the date of the current month
Var d = dd. getDate ();
Date = new Date (y + '-' + m + '-' + d + '00:00:00 ');
Date. setTime (date. getTime (); // 0:00:00 tomorrow
Str + = "; expires =" + date. toGMTString ();
Document. cookie = str;
}

Invalid expiration time set for JS Cookie?

Document. cookie = "user = blue; expires" + oDate;
This sentence is changed
Document. cookie = "user = blue; expires =" + oDate;
A "=" number is missing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.