English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
cookieAttribute retrieval and setting related to the current document's Cookie.
Return cookie properties:
document.cookie
Set cookie properties:
document.cookie = newCookie
var x = document.cookie;Test and see‹/›
You can find more information in ourJavaScript Cookies TutorialLearn more about cookies.
All browsers fully support the following cookie attributes:
Attribute | |||||
cookie | is | is | is | is | is |
Value | Description |
---|---|
newCookie | newCookieis a string in the form ofkey=value. Please note that you can only set/Update a cookie. Any cookie attribute value can be selected to update a cookie.key-valueAfter/Update the cookie and add a semicolon separator in front of it:
Example of creating a cookie: document.cookie="username=Seagull; expires=Thu, 27 Dec 2018 12:00:00 UTC; path=/"; Note: The cookie value string can be usedencodeURIComponent()to ensure that the string does not contain any commas, semicolons, or spaces (commas, semicolons, or spaces are not allowed in cookie values). |
Return value: | a string containing the “ key=value ” cookie for |
---|---|
DOM Version: | DOM 2Level |
Set Cookie:
document.cookie = "name=Seagull"; document.cookie = "favorite_food=Polluted Air";Test and see‹/›