Javascript to read the cookie Function Code. For more information, see. Usage:
1. Set cookie
The Code is as follows:
Var cookie = new JSCookie ();
// Normal settings
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 k3.
Cookie. SetCookie ("key4", "k1 = 1 & k2 = 2 & k3 = 3 ");
Ii. Reading cookies
The Code is as follows:
// Simple retrieval
Cookie. GetCookie ("key1 ");
Cookie. GetCookie ("key2 ");
Cookie. GetCookie ("key3 ");
Cookie. GetCookie ("key4 ");
// Obtain the key 1 Value of key4
Cookie. GetChild ("key4", "k1 ");
Iii. Delete
The Code is as follows:
Cookie. Expire ("key1 ");
Cookie. Expire ("key2 ");
Cookie. Expire ("key3 ");
Cookie. Expire ("key4 ");
Example:
The Code is as follows: