I found the following problem in Safari 5.0 (not in all WebKit-based browsers), this code:
<html> <script> var onstorage = function(evt) { alert([evt.key, evt.oldValue, evt.newValue].join('\n')); } var onclick = function(evt) { localStorage.setItem('test', Math.random()); } var oninit = function() { </script> <body onload="oninit()"> <input id="test" type="button" value="setting a random value"/> </body>
will fire upon warning if we press the button. Although this code is
<html> <script> var onstorage = function(evt) { alert([evt.key, evt.oldValue, evt.newValue].join('\n')); } var onclick = function(evt) { localStorage.setItem('test', Math.random()); } var oninit = function() { window.addEventListener('storage', onstorage, false); </script> <body onload="oninit()"> <input id="test" type="button" value="setting a random value"/> </body>
triggers several warnings as not expected. I think this is a mistake, but someone can not explain to me why replacing only two lines of code leads to such strange behavior?
javascript html5 safari
shabunc
source share