listen to localstorage changes

Solutions on MaxInterview for listen to localstorage changes by the best coders in the world

showing results for - "listen to localstorage changes"
María Alejandra
03 Jun 2018
1window.addEventListener('storage', () => {
2  // When local storage changes, dump the list to
3  // the console.
4  console.log(JSON.parse(window.localStorage.getItem('sampleList')));
5});
Louis
18 Aug 2016
1var originalSetItem = localStorage.setItem;
2
3localStorage.setItem = function(key, value) {
4  var event = new Event('itemInserted');
5
6  event.value = value; // Optional..
7  event.key = key; // Optional..
8
9  document.dispatchEvent(event);
10
11  originalSetItem.apply(this, arguments);
12};
13
14var localStorageSetHandler = function(e) {
15  alert('localStorage.set("' + e.key + '", "' + e.value + '") was called');
16};
17
18document.addEventListener("itemInserted", localStorageSetHandler, false);
19
20localStorage.setItem('foo', 'bar'); // Pops an alert
Lavinia
28 May 2017
1var originalSetItem = localStorage.setItem; 
2localStorage.setItem = function(){
3    document.createEvent('Event').initEvent('itemInserted', true, true);
4    originalSetItem.apply(this, arguments);
5}
6
queries leading to this page
get localstorage when id changesljs listener on change in localstoragejavascript watch for change in localstoragelisten for localstorage changescan others view changes made on local storage jslistyen for local storage changeshow to listen to local storage changenot able to listen to changes in local storafelocalstorage on change javascriptjavascript listen to dom add childrenhow to check local storage data changedlisten to local storage changes javascriptlisten for changes to localstoragelocal storage change listenerhtml listen to storage changelisten to localstorage changesmodify localstorage jslistener for localstorage change javascriptjs local storage change listenerjs localstorage on changewindow on localstorage changeevent localstorage changevue listen listen dom add elementjavascript listen to localstorage changehow to detect change in localstoragejavascript observe localstorage same windowupdate the dom on local storage item changejs on localstorage changelocalstorage value change eventwatch localstorage changeslocalstorage event changelocalstorage change eventwatch localstorage same windowhow to listen for localstorage value changeslocalstorage listen for changesjs listen for changes in value in localstoragejs events on localstorage changesubscibe to storage chanagesjavascript listen for localstorage changechange in local storage event listener localstorage watch for changeslisten to change in local storage javascriptlocalstorage change event examplehow to get local storage changed in javascriptrun function when localstorage item is changedjavascript localstorage change eventhow to listen to localstorage change in jslistn to changes in sessionstoragelisten for localstorage change javascripthow to listen to value changes in localstorageget localstorage change javascript javascript listen localstorage changelisten localstorage changejavascript observe localstoragelocalstorage change listenerlogin page listen change localstorage changewhen storage is changed javascript google chromejs listen localstorage changeweb listen to localstorage changeshandle localstorage changelisten to localstorage changes angularlisten to changes in localstoragedetect localstorage changejs event on local storage changelocal storage listen to updatesjs listen when storage changesjs localstorage listen item changedjavascript how to watch for changes in localstoragereact listen to local storage changeevent to listen localstorage changeslisten local storage value change event javascriptwatch for localstorage changelisten to localstorage changes