This example describes the use of cookie objects in JavaScript. Share to everyone for your reference. Specifically as follows:
Property
Name the only property that must be set to represent the cookieexpires specifies the lifetime of the cookie, if not set, the browser turns off automatic expirationPath determines the availability of cookies to the server for ot
Sorted out two simple JavaScript manipulation cookies, all of which have three functions: setting cookies, querying cookies, and deleting cookies. The first is easy to understand, and the second one is easy to use. Native JS set cookies.
Set Cookies First
Each cookie is a name/value pair, and you can assign a string such as the following to Document.cookie:Document.cookie= "userid=125";If you want to stor
JavaScript and dynamic pages cannot get the time the cookie expires, the browser manages the expiration time, and JavaScript and dynamic pages can only set expiration time. cannot be obtained through Document.cookie (JavaScript) or Cookie.expires (asp.net) properties.
Copy Code code as follows:
This example describes how JavaScript detects whether a browser cookie has started. Share to everyone for your reference. The specific analysis is as follows:
JavaScript detects whether the browser cookie has been started and the code is slightly more complex, by writing a test co
This example describes the JavaScript manipulation cookie method. Share to everyone for your reference. as follows:
My methods for setting, reading and deleting cookies. I have methods to check for the existence of cookies names or values,//To retrieve by name or value, and to create a
formatted string of//All cookies. My site:andrew.dx.am var setcookie = f
The previous article aboutCookieOfArticle, Encapsulates cookie. js. Next we will use an instance to apply this Js.
The most common one is to remember the user name. After a user logs on once, the user's account and password are recorded through cookies, so that the next time the user opens the page, no need to enter the account password again. AttachedCode:
Doctype html > Html Lang = "En-us" > Head > Meta Charset = "UTF-8" >
This article mainly introduces how to implement the Cookie-based storage class in JavaScript. The example analyzes the data storage skills in javascript through cookies, which is very useful, for more information about how to use JavaScript to implement Cookie-based storage,
Cookie Basics in JavaScriptPages are used to store information, such as logging in and remembering user names."Characteristics of cookies"(1) Sharing a set of cookies on all pages of the same website;(2) Limited quantity and size;(3) Have a shelf life, expiration time (by JS Control);(4) A cookie exists on the client."Cookies in JS use"Document.cookie"Set Cookies"(1) Format: First name = value;(2) will not
The following code uses JavaScript to return the comparison of all key values of the current session cookie: javascriptcookie.
This example describes how JavaScript returns the comparison of all key values of the current session cookie. Share it with you for your reference. The details are as follows:
The following J
JavaScript reads and writes the delete cookie operation.
function Getcookieval (offset)Get the value of the cookie after decoding{var endstr = document.cookie.indexOf (";", offset);if (endstr = = 1)Endstr = Document.cookie.length;Return unescape (document.cookie.substring (offset, endstr));}---------------------------function Setcookie (name, value)Set
In JavaScript, arrays are not stored directly as cookies (PHP can), and that is to dump the array into a string, and then save it in a cookie, and we can use either ToString () or join directly on the simple one-dimensional array:
The ToString function method in JavaScript is a string representation of the returned object.
How to use: objectname.tostring ([radix]
The example in this article describes the Java implementation of a cookie-based storage class. Share to everyone for your reference. The specific analysis is as follows:
Through this JS class, you can use the same as the session cookie, very simple!
* * Cookiestorage.js * This class implements the same storage API * as Localstorage and Sessionstorage, which is based on HTTP cookies. */function Cookies
Below
Code:
Copy codeThe Code is as follows:
The usage is like this.Setmycookie ('name'); in this way, a cookie named name is set under the domain name.PHP is easier to read.Copy codeThe Code is as follows: $ STR = $ _ cookie ('name'); // The parameter in it is the name set above.?>
Reposted from 5d happy blogBelow are some supplementary knowledge. For more information, see.Set and read the
How does one return the comparison of all key values of the current session cookie using JavaScript?
The following JS Code outputs all cookie key-Value Comparison
1 2 3 4 5 6 7 8 9
Cookies associated with this document:
The output result on the local machine is as follows;
The Code is as follows:Cookies associated with th
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.