Entry
How to check if the browser accepts cookies?
Mar 3rd, 2000 20:16
Martin Honnen,
To check whether cookies are accepted you set a test cookie and look
whether it got set:
var cookieName = 'testCookie' + (new Date().getTime());
document.cookie = cookieName + '=cookieValue';
var cookiesEnabled = document.cookie.indexOf(cookieName) != -1;
if (cookiesEnabled)
// ...
else
// ...
Note that browsers (at least NN) have a possible user setting to ask
the user for every cookie whether to accept it. With this setting it is
of course possible that the test cookie gets accepted but later
attempts to use cookies are cancelled by the user.
If you write IE only code you can also check
navigator.cookieEnabled