Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localStorage in win8.1 IE11 does not synchronize

We have two pages "/read" and "/write". Page "/write" each second updates localStorage with current time:

setInterval(function(){
    var time = (new Date()).getTime();
    localStorage.setItem("time", time);
    console.log("set", time);
},1000);

Page "/read" reads same storage:

setInterval(function(){
    var time = localStorage.getItem("time");
    console.log("get", time);
},1000);

One would think that "/read" page should show the same values which are written to localStorage by another page. But in IE11 on Win8.1 this is broken. Page "/read" reads some old value from storage, and further on it will show you the same value (as if it uses cache for local storage). Any ideas?

P.S. Both pages are on the same domain (live example - read write)

like image 841
developer Avatar asked Jun 06 '14 08:06

developer


People also ask

Does IE support localStorage?

IE also supports localStorage from IE8 but it does not support localStorage in IE7 and previous versions. Cookies are small text files stored by browsers allowing for a max of 4KB while with localStorage we can store Mbs of localStorage data.

Is localStorage sync or async?

Nope, all localStorage calls are synchronous.

Is localStorage shared between Windows?

The main features of localStorage are: Shared between all tabs and windows from the same origin. The data does not expire. It remains after the browser restart and even OS reboot.


1 Answers

I've found a workaround for this issue on Win 10. If you handle the window.onstorage event in your code then localStorage will refresh for all open tabs. Something as simple as this worked for me:

window.onstorage = function(e){
    //Leave this empty
    //or add code to handle
    //the event
};

I haven't tested this code thoroughly, so please do so before using this method in any production apps.

Hope this helps!

like image 123
Christopher Brown Avatar answered Oct 17 '22 03:10

Christopher Brown