如何使用 JavaScript 检查 cookie 是否被阻止?
1 回答
5
写一个cookie然后读取它......
例如:
函数 readCookie(cname) {
a = 修剪(document.cookie);
水库='';
而(一个!=''){
cookiename = a.substring(0,a.search('='));
cookiewert = a.substring(a.search('=')+1,a.search(';'));
if(cookiewert == '' || a.search(';')==-1) {
cookiewert = a.substring(a.search('=')+1,a.length);
} 别的 {
cookiewert = a.substring(a.search('=')+1,a.search(';'));
}
if(cname == trim(cookiename)){
res = cookiewert;
返回(资源);
}
i = a.search(';')+1;
如果(i == 0){i = a.length}
a = a.substring(i,a.length);
}
返回(资源)
}
函数 checkSessionCookie() {
//写入cookie
document.cookie = 'sessioncookieallowed=true;';
var check = readCookie('sessioncookieallowed');
}
调用函数 checkSessionCookie();
于 2008-11-05T12:24:51.687 回答