Detect if the browser supports cookies
function Checkcookie () {
To determine whether a cookie is turned on
var cookieenabled= (navigator.cookieenabled)? True:false;
If the browser is not ie4+ or ns6+
if (typeof navigator.cookieenabled== "undefined" &&!cookieenabled) {
Document.cookie= "TestCookie";
Cookieenabled= (document.cookie== "TestCookie")? True:falsedocument.cookie= "";
}
If it's not turned on
if (cookieenabled) {
return true;
}else{
return false;
}
}
Add cookies
function Addcookie (name,value,expirehours) {
var cookiestring=name+ "=" +escape (value);
Determine whether to set an expiration time
if (expirehours>0) {
var date=new date ();
Date.settime (date.gettime+expirehours*3600*1000);
Cookiestring=cookiestring+ "; Expire= "+date.togmtstring ();
}
document.cookie=cookiestring;
}
Get Cookie Value
function GetCookie (name) {
var Strcookie=document.cookie;
var arrcookie=strcookie.split (";");
for (Var i=0;i<arrcookie.length;i++) {
var arr=arrcookie[i].split ("=");
if (arr[0]==name) {
Return unescape (arr[1]);
}
}
return false;
}
Delete Cookies
function Deletecookie (name) {
var date=new date ();
Date.settime (Date.gettime ()-10000);
Document.cookie=name+ "=; Expire= "+date.togmtstring ();
}
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.