0

i am using

 navigator.cookieEnabled

in JavaScript to determine whether cookies enabled or not on client. its working fine on all browsers except IE. Please help am i using wrong method for identifying about cookies is there something wrong with IE 10

aleation
  • 4,796
  • 1
  • 21
  • 35
Rutu
  • 147
  • 2
  • 10

1 Answers1

0

The most reliable way I can think of to check whether cookies are enabled is to set a cookie in your response from the server in the first place, and check that it's set on the client via document.cookie. According to this answer to another question, there's no point in checking cookieEnabled, it doesn't provide correct information.

For instance, if your server includes this header in the response serving the page:

Set-Cookie: cc=1; Max-Age=3600

...then your JavaScript code can check like this:

if (/\bcc=/.test(document.cookie)) {
    // They appear to be enabled
} else {
    // Not so much
}
Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • i am checking for cookie on login page itself on click of login button . My problem is it works fine in chrome, firefox but not in IE – Rutu Mar 10 '14 at 08:25
  • @Rutu: By "it" do you mean `cookieEnabled`? That's why I'm suggesting actually checking for a cookie. Nothing says "cookies are/aren't enabled" like "I do/don't see a cookie I set." – T.J. Crowder Mar 10 '14 at 08:27
  • even if i enable cookies on IE still it gives false in IE 10. Am i missing anything – Rutu Mar 11 '14 at 12:37