Web page special effects cookies read and write program
Here introduced the next about cookies by the implementation of JS, mainly delete, settings, read the cookie code, the need for friends can refer to.
Write cookies function
function Setcookie (name, value)//two parameters, one is the name of the cookie, one is the value
{
var days = 30; This cookie will be saved for 30 days
var exp = new Date (); New Date ("December 31, 9998");
Exp.settime (Exp.gettime () + days * 24 * 60 * 60 * 1000);
Document.cookie = name + "=" + Escape (value) + "expires=" + exp.togmtstring ();
}
function GetCookie (name)//Read cookies functions
{
var arr = Document.cookie.match (New RegExp ("(^|)" + name + "= ([^;] *)(;|$)"));
if (arr!= null) return unescape (arr[2)); return null;
}
function Delcookie (name)//Delete cookie
{
var exp = new Date ();
Exp.settime (Exp.gettime ()-1);
var cval = GetCookie (name);
if (cval!= null) Document.cookie = name + "=" + Cval + "; expires=" + exp.togmtstring ();
}
$ ("#input_SmallImgUrl"). Val (GetCookie ("Smallimgurl"));
Setcookie ("Simage", $ ("#ImgUrl"). attr ("src"). toString ());
$ ("#ImgUrl"). attr ("src", GetCookie ("Simage"));