faqts : Computers : Programming : Languages : JavaScript : Browser Settings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

142 of 184 people (77%) answered Yes
Recently 4 of 10 people (40%) answered Yes

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