How to add a Cookie in the browser

Document.cookie may be used, the property is readable and writable, read is not read all of the provided cookie HttpOnly returned as a string, a write is to write a cookie to document.cookie, it is noted that additional write not covered, but can only write a cookie specific example is as follows: 

document.cookie = 'fontSize=14; '
  + 'expires=' + someDate.toGMTString() + '; '
  + 'path=/subdirectory; '
  + 'domain=*.example.com';

 

note: 

1. Path property must be an absolute path, the default is the current path;

2. Domain attribute values must be part of the current send the cookie domain name;

3. Max-Age attribute value is in seconds;

4. the Expires attribute value is a date time string UTC format can convert Date.prototype.toUTCString ();

 

Guess you like

Origin www.cnblogs.com/aisowe/p/11567120.html