navigator.cookieEnabled无法在localhost中的IE9中工作 [英] navigator.cookieEnabled not working in IE9 in localhost
问题描述
我正在使用asp.net,在我的logon.aspx页面中,我从以前的问题/答案中复制了以下代码:
是否可以检查cookies是否启用了modernizr?
I am working with asp.net, and in my logon.aspx page I have the following code copied from a previous question/answer: is it possible to check if cookies are enabled with modernizr ?
function are_cookies_enabled() {
var cookieEnabled = (navigator.cookieEnabled) ? true : false;
if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
document.cookie = "testcookie";
cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
}
return (cookieEnabled);
}
但是当我运行我的本地服务器(Visual Studio 2010集成的服务器)时,变量cookieEnabled总是为false,但它只发生在我的localhost中,当我在 jsfiddle 中尝试相同的代码时工作得很好。 (上面的代码适用于除IE9之外的所有浏览器,在localhost中)
任何想法??
But when I run my local server (the Visual Studio 2010 integrated one), the variable cookieEnabled is always false, but it is only happening in my localhost, when I tried the same code in jsfiddle it works perfectly. (the above code works for all the browsers except in IE9, in localhost) Any idea??
推荐答案
尝试
选项1: http://127.0.0.1 /
而不是 http:/ / localhost:5130 /
ie;只是在浏览器上禁用cookie只会设置互联网设置
option 1: http://127.0.0.1 /
instead of http://localhost:5130/
ie; just disabling cookie on your browser will only set internet settings
所以给IP地址 - >开始 - >运行 - > Cmd->输入ipconfig然后你会看到你的IP地址如下所示
So give IP adress -> Start-> Run->Cmd->Type ipconfig then you will see your IP adresses shown below
选项2
http://IPADRESS/app/urpag.aspx
然后查看以下javascript
then check with below javascript
<script type="text/javascript">
document.write("Cookies enabled: " + navigator.cookieEnabled);
</script>
这篇关于navigator.cookieEnabled无法在localhost中的IE9中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!