1, jquery cookie packet implementation of mobile phone floating layer ads
<span style= "FONT-SIZE:18PX;"
>$ (document). Ready (function () {//Encyclopedia observation floating layer AD var Adcookie=$.cookie ("Doccookie");
If there is no cookie locally, the entry cookie is written to the local if (adcookie!= "Addoccookie") {$ ("#wapDocCookie"). Show ();
///If there is a local entry cookie, the floating layer if (adcookie== "Addoccookie") {$ ("#wapDocCookie") is not displayed. Hide ();
//close advertisement, hide floating layer $ ("#closeAd"). Click (function () {$ (#wapDocCookie). Hide ();
$.cookie ("Doccookie", "Addoccookie", {expires:60});
});
}); JQuery Cookie Library Jquery.cookie = function (name, value, options) {if (typeof value!= ' undefined ') {//name an D value given, set cookie options = Options | |
{};
if (value = = null) {value = ';
Options.expires =-1;
} var expires = '; if (Options.expires && (typeof options.expires = = ' Number ' | | | options.expires.toUTCString)) {var date
;
if (typeof options.expires = = ' number ') {Date = new Date ();
Date.settime (Date.gettime () + (Options.expires * 24 * 60 * 60 * 1000));
else {date = Options.expires; } expires = '; Expires= ' + date.toutcstring (); Use expires attribute, Max-age isn't supported by IE} var path = Options.path? ';
Path= ' + (Options.path): '; var domain = Options.domain? ';
Domain= ' + (options.domain): '; var secure = options.secure? ';
Secure ': ';
Document.cookie = [name, ' = ', encodeURIComponent (value), expires, path, domain, Secure].join (');
else {//only name given, get cookie var cookievalue = null;
if (document.cookie && document.cookie!= ') {var cookies = Document.cookie.split (';');
for (var i = 0; i < cookies.length i++) {var cookie = Jquery.trim (Cookies[i]);
Does this cookie string begin with the name we want? if (cookie.substring (0, name.length + 1) = = (name + ' = ')) {cookievalue = decodeURIComponent (cookie
. substring (name.length + 1));
Break
}} return cookievalue; }};</span>
2.js cookies to implement floating layer advertisement on mobile phone
<span style= "FONT-SIZE:18PX;" >$ (document). Ready (function () {
function Writecookie (name,value)
{
var exp = new Date ();
Exp.settime (Exp.gettime () + 7*24*60*60*1000);
Document.cookie = name + "=" + Escape (value) + "expires=" + exp.togmtstring ();
}
Read Cookies
function Readcookie (name)
{
var arr,reg=new RegExp ("(^|)" +name+ "= ([^;] *)(;|$)");
if (Arr=document.cookie.match (reg)) {return
unescape (arr[2]);
} else {return
null;
}
}
var Doccookie = Readcookie ("Doccookie");
var docfootads = $ ("#guancha_foot_ads");
if (doccookie!= "Docwirtecookie") {
alert (Doccookie);
Writecookie ("Doccookie", "Docwirtecookie");
Docfootads.show ();
}
if (doccookie== "Docwirtecookie") {
alert (Doccookie);
Docfootads.hide ();
}
Close the ad, hide the floating layer
$ ("#closeAd"). Click (function () {
$ ("#wapDocCookie"). Hide ();
}
); </span>
3. On-line JS operation Cookie Information
JS Get Cookie
<span style= "FONT-SIZE:18PX;" >//js Get Cookie
/* Get cookie value
/function GetCookie (c_name)
{
if (document.cookie.length>0) {
C_start=document.cookie.indexof (c_name + "=")
if (c_start!=-1) {
C_start=c_start + c_name.length+1
C_end=document.cookie.indexof (";", C_start)
if (c_end==-1) c_end=document.cookie.length return
unescape ( Document.cookie.substring (c_start,c_end)
}
} return
""
}</span>
JS Operation Cookie Method! *****************************************************************
<span style= "FONT-SIZE:18PX;"
>//Write Cookies function Setcookie (name,value) {var days = 30;
var exp = new Date ();
Exp.settime (Exp.gettime () + days*24*60*60*1000);
Document.cookie = name + "=" + Escape (value) + "expires=" + exp.togmtstring (); //Read cookies function GetCookie (name) {var arr,reg=new RegExp ("(^|)" +name+ "= ([^;]
*)(;|$)");
if (Arr=document.cookie.match (reg)) return unescape (arr[2]);
else return null;
//Delete the cookie function Delcookie (name) {var exp = new Date ();
Exp.settime (Exp.gettime ()-1);
var cval=getcookie (name);
if (cval!=null) document.cookie= name + "=" +cval+ "; expires=" +exp.togmtstring ();
//Use sample Setcookie ("name", "Hayden");
Alert (GetCookie ("name"));
If you need to set the custom expiration//Then replace the above Setcookie function with the following two functions on OK;
Program code function Setcookie (name,value,time) {var strsec = getsec (time);
var exp = new Date ();
Exp.settime (Exp.gettime () + strsec*1); Document.cookie = name + "=" + Escape (value) + "expires=" + exp.togmtstring ();
function Getsec (str) {alert (str);
var str1=str.substring (1,str.length) *1;
var str2=str.substring (0,1);
if (str2== "s") {return str1*1000;
else if (str2== "H") {return str1*60*60*1000;
else if (str2== "D") {return str1*24*60*60*1000; }//This is an example of a set expiration time://S20 is for 20 seconds//h refers to hours, such as 12 hours is: H12//d is the number of days, 30 days: D30 Setcookie ("name", "Hayden", "S20");</span>