正在检查在IE8中使用Javascript启用的Cookie [英] Checking for cookies being enabled in IE8 using Javascript
问题描述
我在Firefox 3中使用以下代码正常工作:
var cookieEnabled =(navigator.cookieEnabled)?真假;
// if not IE4 + as NS6 +
if(typeof navigator.cookieEnabled ==undefined&&!cookieEnabled){
document.cookie =testcookie;
cookieEnabled =(document.cookie.indexOf(testcookie)!= - 1)?真假;
}
从我所看到的这似乎是合理建立的方法检查Cookie支持是否打开?但是,它拒绝在IE8中工作,当我关闭cookie,并运行此代码cookiesEnabled总是等于true。
任何想法?
谢谢。
我正在通过导航到 http:// localhost ...
来测试我的软件。当然,IE将这个区域视为本地Intranet区域,不会将我的设置应用于Cookie,因此允许它们。
如果我转到我的实际IP地址通过本地环回它被视为互联网区域和工作正常:)
Doh!
I am attempting to check whether cookies are enabled or not using Javascript, cross-browser.
I have got this working fine in Firefox 3 using the following code -
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;
}
And from what I've seen this seems to be the reasonably established method of checking for cookie support being turned on? However, it refuses to work in IE8, when I turn off cookies in that and run this code cookiesEnabled always equals true.
Any ideas?
Thanks.
Ah found the problem. I was testing my software by navigating to http://localhost...
Of course IE treats this as the Local Intranet Zone and doesn't apply my settings for cookies, so allowing them regardless!
If I navigate to my actual IP address via the local loopback it treated it as internet zone and worked fine :)
Doh!
这篇关于正在检查在IE8中使用Javascript启用的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!