Skip to content

Instantly share code, notes, and snippets.

@ShivrajRath
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save ShivrajRath/9944dce699bbae12f614 to your computer and use it in GitHub Desktop.

Select an option

Save ShivrajRath/9944dce699bbae12f614 to your computer and use it in GitHub Desktop.
'Storage' Event on localstorage
/**
* This is called when setItem(), removeItem(), or clear() changes something on localstorage
* This event not triggered for the tab/window where the event is initiated. It is triggered in other tabs
*/
localStorage.setItem('locKey', '1');
var fn = function (event) {
if (event.key == 'locKey') {
console.log("Old Value : " + event.oldValue);
console.log("New Value : " + event.newValue);
console.log("Url : " + event.url);
}
};
window.addEventListener('storage', fn, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment