我正在尝试使用Javascript,跨浏览器检查Cookie是否已启用。
我使用以下代码在Firefox 3中正常运行 -
var cookieEnabled=(navigator.cookieEnabled)? true : false;
//if not IE4+ nor NS6+
if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){
document.cookie="testcookie";
cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false;
}
从我所看到的,这似乎是检查开启cookie支持的合理建立的方法?但是,它拒绝在IE8中工作,当我关闭cookie并运行此代码时,cookiesEnabled总是等于true。
有什么想法吗?
感谢。
答案 0 :(得分:3)
当然,IE将其视为本地Intranet区域,并且不会将我的设置应用于Cookie,因此无论如何都允许它们使用!
如果我通过本地环回导航到我的实际IP地址,它会将其视为互联网区域并且工作正常:)
卫生署!