This article mainly introduces the JavaScript cookie operation class. Examples of common javascript techniques for cookie setting, reading, and deletion are analyzed, which is of great practical value, for more information, see the example in this article. Share it with you for your reference. The details are as follows:
Usage:
1. Set cookie
Var cookie = new JSCookie (); // set the cookie. setCookie ("key1", "val1"); // The expiration time is one year var expire_time = new Date (); expire_time.setFullYear (expire_time.getFullYear () + 1); cookie. setCookie ("key2", "val2", expire_time); // set the domain and path with the expiration time cookie. setCookie ("key3", "val3", expire_time, ".cnblogs.com", "/"); // set the cookie of the BIND key. The subkeys are k1, k2, and k3cookie. setCookie ("key4", "k1 = 1 & k2 = 2 & k3 = 3 ");
Ii. Reading cookies
// Obtain the cookie. getCookie ("key1"); cookie. getCookie ("key2"); cookie. getCookie ("key3"); cookie. getCookie ("key4"); // obtain the key-1 cookie of key4. getChild ("key4", "k1 ");
Iii. Delete
cookie .Expire("key1");cookie .Expire("key2");cookie .Expire("key3");cookie .Expire("key4");
Example: