HTML
<div class="section">
<div id="js-div"> </div>
<div id="js-log">Log ... <br/></div>
</div>
<div class="section">
<div class="summary">This test creates that the "onstorage" event is called during set and get items onto the browser localStorage</div>
</div>
Javascript
function store() {
if (window.localStorage) {
var count=window.localStorage.getItem("count");
if (!count) {
count=0;
}
count++
window.localStorage.setItem("count",count);
document.getElementById("js-div").innerHTML="<i>Count = " + count + "</i>";
} else {
document.getElementById("js-div").innerHTML="<i>Local Storage not available</i>";
}
}
function log(a) {
document.getElementById("js-log").innerHTML+= a + "<br/>";
}
function handleOnStorage() {
if (!window.event) {
log("window event not available.");
} else {
log("onStorage event trapped");
log("item name = " + event.key);
log("+ new value = " + event.newValue);
log("+ old value = " + event.oldValue);
}
}
window.onload = function() {
log("onStorage test starting ...");
document.body.setAttribute("onstorage", "handleOnStorage();");
store();
log("onStorage test finished ...");
}