I have encountered the following problem in Safari 5.0 (not all WebKit-based browsers), this code:
& lt; Html & gt; & Lt; Script & gt; Var onstorage = function (evt) {warnings ([[evt.key, evt.oldValue, evt.newValue]. ('\ N')); } Var onclick = function (evt) {localStorage.setItem ('test', Math.random ()); } Var oninit = function () {// In fact, it works the same way with the old "plain event" onclick document .query selector ('# test'). AddEventListener ('click', onclick, false); Window.addEventListener ('storage', onstories, incorrect); } & Lt; / Script & gt; & Lt; Body onload = "oninit ()" & gt; & Lt; Input id = "test" type = "button" value = "set a random value" /> & Lt; / Body & gt;
will trigger an alert if we click on the button while this code -
& lt; Html & gt; & Lt; Script & gt; Var onstorage = function (evt) {warnings ([[evt.key, evt.oldValue, evt.newValue]. ('\ N')); } Var onclick = function (evt) {localStorage.setItem ('test', Math.random ()); } Var oninit = function () {window.addEventListener ('storage', onstorage, false); // In fact, it works similarly with the old "plain event" onclic document. Choir selector ('# test') AddEventListener ('click', onclick, falls); } & Lt; / Script & gt; & Lt; Body onload = "oninit ()" & gt; & Lt; Input id = "test" type = "button" value = "set a random value" /> & Lt; / Body & gt;
triggers some alerts, as expected, I think this is a bug, but no one can explain to me - code in such a strange behavior Why the result of swapping two lines?
There are no bugs (though others have commented that I have handled event handlers with global names Can not name names as tasks).
The problem is how the notification works for local storage. In short, the events are removed only for other windows (or tabs) that have the same local storage Use.
Here is the stack overflow here.
For example, the storage changed event will not be fire: the handler is on the same page.
Comments
Post a Comment