问题
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);
}
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:
Try
option 1: http://127.0.0.1 / instead of http://localhost:5130/ ie; just disabling cookie on your browser will only set internet settings
So give IP adress -> Start-> Run->Cmd->Type ipconfig then you will see your IP adresses shown below
option 2
http://IPADRESS/app/urpag.aspx
then check with below javascript
<script type="text/javascript">
document.write("Cookies enabled: " + navigator.cookieEnabled);
</script>
回答2:
I managed to lock out my previously working IE9 so that if security zone is Local Intranet, it will report:
navigator.cookieEnabled == false
If I change the zone to Internet and protected mode on, the cookies are enabled. Before this happened, I did change the privacy settings. I have no idea how to get it back. Perhaps a re-install would help.
来源:https://stackoverflow.com/questions/9364279/navigator-cookieenabled-not-working-in-ie9-in-localhost