Document.cookie is still available in IE11 although cookies are disabled

Using IE11, I can display the content of all cookies, write out cookies, find them and delete them using JavaScript, even though I have my privacy set to "Block all cookies". (And in fact, no matter which version I configured my IE emulation on, document.cookie still works.) It works like it does in Chrome with cookies disabled - i.e. document.cookie returns empty / nothing when I try to link to it in the same JavaScript.

I am trying to determine if a user's cookie is disabled in their IE. (Old ASP application that requires IE with cookies. No JQuery. No Modernizr.) For this I try to write out a cookie, find it and delete it. This either works or it doesn't - which should tell me if cookies are on or off. Any ideas? I thought this was the safest way to define custom IE cookie settings.

My code:

<script language=javascript>
     cookiesON = false;
     if ("cookie" in document ) {
         alert("1. document.cookie (before add): " + document.cookie);

         var dateNow = new Date();
         document.cookie = "testcookie=" + new Date()
         alert("2. document.cookie (after add): " + document.cookie);

         if (document.cookie.indexOf("testcookie=") > -1) {
            cookiesON  = true;
         } else {
            cookiesON  = false;
         }

         // delete cookie: set cookie to expire 2 minutes ago
         document.cookie="testcookie=xx; expires=" + (new Date(dateNow.getTime() - 2*60000).toGMTString());
         alert("3. document.cookie (after delete): " + document.cookie);
      }

      

In IE: All 3 warnings show values ​​for document.cookie regardless of whether cookies are enabled or disabled. You can see the test app has been added and removed.

In Chrome: All 3 warnings show blank for document.cookie when cookies are disabled. Works as described for IE when cookies are enabled.

+3


source to share





All Articles