Checking the inclusion of cookies in IE8 using Javascript

I am trying to check whether cookies are enabled or not using Javascript cross browser.

I have this work 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 saw, is this apparently a reasonably established method for checking whether cookies are enabled? However, it refuses to work in IE8 when I turn off the cookies in this and run this code. CookieEnabled is always true.

Any ideas?

Thanks.

+4
source share
1 answer

I found a problem. I tested my software by going to http: // localhost ...

Of course, IE sees this as a local intranet zone and does not apply my cookie settings, so it allows them independently!

If I go to my actual IP address through a local loopback, it processed it as an Internet zone and worked fine :)

Doh!

+3
source

Source: https://habr.com/ru/post/1303773/


All Articles