I have the following sample code (hosted at https://d-dsuo5j1fc.now.sh/) which should show 2 constantly changing date strings. The first is in a simple 500ms loop, the second is the result of a StorageEvent. The idea is that this page is loaded in two tabs such that each tab is alerted to a localstorage change in the other tab.
It works fine in Chrome/iOS, but in Safari iOS, the second string is never updated, suggesting that it didn't fire the onStorage event.
<body>
Own timer<span id='s'> </span><br>
From storage event <span id='ev'> </span>
</body>
<script>
let s = document.getElementById('s');
let ev = document.getElementById('ev');
function onStorageEvent(storageEvent){
ev.innerHTML = storageEvent.newValue; // display the storage event value
}
window.addEventListener('storage', onStorageEvent, false);
// every 500ms, generate a new string, display it and write it to localstorage
setInterval(()=>{
let d = new Date().toGMTString() + ' ' + Math.random();
s.innerHTML = d; // display our fresh value
localStorage.setItem('foo',d); // and write it to localstorage
}
,500);
</script>
Also, any suggestions for a good resource for the HTML5 incompatibilities of Safari on iOS?
from does iOS Safari support storageEvents?
No comments:
Post a Comment