Javascript, IE9 and Cookies - A simple mess story

Well if you have mugged the following syntax to add cookie in javascript ,

document.cookie="cookieName=cookieValue;expires=0;path=/;domain=.cookieDomain";

There is a bad news for you. This works good with Firefox and chrome but IE is no more gentle with this syntax. Don't know since which version IE starting misbehaving with JS cookies but IE9 is really stubborn.

IE9 rejects the use of expires=0 or expires=Thu, 01-Jan-1970 00:00:01 GMT  for session cookies as it treats them as cookies which are already expired :)

one can either specify a hard future date or just leave this blank to keep IE9 happy.

The other problem with specifying localhost domain ie domain=localhost as IE treats localhost differently from real domains.

So if you are in love with IE just keep it simple :)

document.cookie="cookieName=cookieValue;path=/";

rest IE should take care.  Hope so .....

For details and answers to further questions visit the following post. It should answer your IE cookie issues.

IE Cookie Internals -

http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx