Link to home
Start Free TrialLog in
Avatar of ccaprar
ccaprar

asked on

How can I detect if session cookies are disabled?

How can I detect from client side JavaScript that session cookies are disabled?

Persistent cookies can be detected with navigator.cookieEnabled, but session cookies not.

And you can disable them easy in IE up to 6 and not so easy on IE 6 and up. Also easy on Netscape.

A server solution is not acceptable (it includes writing a cookie and redirecting to check it).
Avatar of ahosang
ahosang
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm not sure i agree with you. If navigator.cookieEnabled returns true, that means the browser is accepting cookies(maybe options for third party etc). There may be an option to accept session cookies but not persistent, but I don't recall any user setting which allows persistent but not session cookies.
Avatar of ccaprar
ccaprar

ASKER

Hello,

At least as IE 5 is concerned, you can disable separately both types of cookies.
In IE6, you can do this also, but using the Privacy settings.

MSDN states that navigator.cookieEnabled ignores session cookies....
I'm not sure I understood your question, but
why don;t you try, seting a cookie , then issue
a <META> tag with a refresh argument, and on
next page, try to get the cookie, if it is available
it may be an incicator that cookies are enabled...

if not, you can then for example redirect to another
page using again the <META> tag.

Hope it helps.

I think you may be unclear on the timing difference between server set and client-side JS set cookies.  When you set from the server you use HTTP headers, and can't read them on the same page (need that redirect).  But that's not the case with JS set cookies.  You can set the cookie (and set is as a session cookie) and then try to read from it all on the same page.  If you can't read from it after it's set, then their cookies are disabled.

Now of course... that raises the issue of how do you tell if JS is enabled, which is another story.  Unless you really only care about the combo of JS + cookies, in which case on JS cookie test will tell you everything (have the test change a form field to 'enabled' from 'disabled' if the test succeeds to get the info back to server side).

Don't rely on META Refresh.... the META Refresh can also be disabled in the browser completely separately from JS or cookies so your test could fail even if the condition you were testing for was true.
Avatar of ccaprar

ASKER

Hi memerot.

Asuming that I have JS enabled, how can I detect in JS if a session cookie and a persistent cookie are allowed? Can you give me a small code example?

Thanks,
Cristi
ASKER CERTIFIED SOLUTION
Avatar of spo0ky
spo0ky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ccaprar

ASKER

Thanks, I will check that.
no problems