<html> <head> </head> <body> <script> var storage = window.localStorage; function readStoredData(event) { var key = event.key; var newValue = event.newValue; if (key == "testData") { var newData = JSON.parse(newValue); console.log("New Data: " + newData.length); } if (key == "testString") { console.log("String: " + newValue); } } window.addEventListener("storage", readStoredData, false); var data = []; for (var i = 0; i < 200; i++) { data.push({ id: i, message: "Message №" + i }); } storage.setItem("testData", JSON.stringify(data)); storage.setItem("testString", "string"); </script> </body> </html> 

When saving a small string, the event is generated, but when I try to save a large array, the event is not generated, and the array is saved.

Ps IE browser

  • Your code in IE version 11.0.9600.17843 is stable. - pavelip

1 answer 1

Because IE is sad.

The storage events in IE 10-11 are very buggy, and if there is any possibility to do without them, it is better to do without them. This is one of the common bugs.

If you really need to write something big in localStorage, you will have to write piece by piece, like here .

By the way, for those who need to work with storages in IE, several known troubles with localStorage in the donkey are described on caniuse.com