document.cookie = "mycookiename=value; expires=some gmt date time; path=thepath; domain=the domain";
Therefore, if we wanted to set a session only cookie, we can set something like this:
document.cookie = "mtracker=somevalue; expires=0; path=/";
It looks like the PHP equivalent isn’t it?
The above code snippet works flawlessly in Firefox and Google Chrome. However, it expires immediately as soon as it is set in Internet Explorer. My Google Kung-Fu didn’t work this time and ask a colleague to help debug the issue.
The problem was that Internet explorer has different interpretation with the
expires parameter. Instead of giving ZERO to expire, we will leave it out completely. This should be the syntax in most cases.
document.cookie = "mtracker=somevalue; path=/";
That’s it! Be gentle to our friend IE.