Html – Cookies and multiple browser windows/tabs

cookieshtmljqueryjquery-cookie

I'm trying to share some information between browser windows/tabs, and I'm leery of HTML5 local storage because of browser support issues. Some googling lead me to believe cookies can be used for this, so I grabbed jquery.cookie and set up a simple test.

Two pages which write a cookie when loaded:

$.cookie("testValue", new Date().getTime());

and a button that displays the cookie value in an alert on each:

alert($.cookie("testValue"));

When testing, I see different values on each page, which would lead me to believe this just doesn't work, but I keep running across posts here and elsewhere where people seem to be recommending it, so I'm wondering if I'm just doing something wrong?

Best Answer

Cookies are only updated in the JavaScript environment when set by JS, or when the page loads.

localStorage was designed for this. IE8 supports it just fine, it's only the really old IE7 and below that don't. Although IE9 is Windows-Vista-and-7-only, IE8 is fine on XP so you should have no troubles asking your users who are still on archaic browsers to update.

(I can't say this enough, but IE really need an auto-updater like all other browsers...)