I added an eventListener to the window DOM-Object and want to keep track of the changes made to localStorage.
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script language="JavaScript"><!--
window.addEventListener('storage', storageEventHandler, false);
function storageEventHandler(evt){
console.log("oldValue: " + evt.oldValue );
console.log("storage event called key: " + evt.key );
console.log("newValue: " + evt.newValue );
}
$(document).ready(function(event) {
$('#link1').click(function(event){
event.preventDefault();
localStorage.setItem('page', 2000);
console.log(localStorage.getItem('page'));
});
$('#link2').click(function(event){
event.preventDefault();
localStorage.setItem('page', 998);
console.log(localStorage.getItem('page'));
});
});
</script>
</head>
</html>
Somehow the storageEventHandler is never called even though the localStorage value is changed when I click link1 or link2. Any help is much appreciated.
storage
event gets fired, depends on the browser. – Cords