The following sample works fine in Firefox, but doesn't work at Chrome.
<!doctype html>
<meta charset="utf-8">
<textarea id="out" cols="80" rows="20"></textarea>
<br>
<p>
Text to send:
<input id="in" type="text" size="60">
<button id="btnSend">Send</button>
<button id="btnClear">Clear</button>
</p>
<script>
btnClear = document.getElementById("btnClear");
btnSend = document.getElementById("btnSend");
inp = document.getElementById("in");
out = document.getElementById("out");
var handle_storage = function (event) {
if (event.key == "message") { out.value += event.newValue + "\n";}
};
window.addEventListener("storage", handle_storage, false);
btnSend.onclick = function() {
localStorage.setItem('message', inp.value);
out.value += inp.value + "\n";
inp.value = "";
};
btnClear.onclick = function() {
inp.value = "";
out.value = "";
};
</script>
Here is a kind of text chat. handle_storage
fires in the second tap or window of Firefox, but it doesn't fire in any tab or window of Chrome.
How to fix?