0

I am trying to detect if the cookies are enabled using Javascript. And my code seems to work for all browsers except Internet Explorer 11.

This is the method I am using

function checkCookie() {
    var cookieEnabled = navigator.cookieEnabled;
    if (!cookieEnabled){
        document.cookie = "testcookie";
        cookieEnabled = document.cookie.indexOf("testcookie")!=-1;
    }
    return cookieEnabled;
}

To detect cookies for IE, I already tried the suggested solutions from

Detect if Cookies are enabled in IE 11 using JS and Check if cookies are enabled

However, even though the cookies (1st party and 3rd party) are disabled, checkCookie() always returns true

Thank you

Rahul Vala
  • 695
  • 8
  • 17
  • IE always returns `true` for `navigator.cookieEnabled`, even if you block all cookies, so ignore the output of that and always use the cookie setting test. – Heretic Monkey Oct 23 '20 at 16:57
  • @HereticMonkey unfortunately, the cookie setting test returns true every time for IE – Rahul Vala Oct 23 '20 at 17:12
  • Then perhaps cookies aren't as disabled as you think they are? When I tested it in IE with first and third party cookies blocked, and "Always allow session cookies" unchecked, it returned `false` using the setting test. Note that you need to make sure that cookie is deleted before running the test... – Heretic Monkey Oct 23 '20 at 17:20
  • 1
    I use the test method in [this link](https://stackoverflow.com/questions/42226920/detect-if-cookies-are-enabled-in-ie-11-using-js) and it works for IE. Please notice that don't test it on localhost, you need to serve the test page on the Internet and make sure it's not in the trusted sites list. I find that it will always be true if you test it on localhost or on a trused site. – Yu Zhou Oct 26 '20 at 05:57

0 Answers0