js listen localstorage change

Solutions on MaxInterview for js listen localstorage change by the best coders in the world

showing results for - "js listen localstorage change"
Henri
08 Mar 2016
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});
Sophie
07 Sep 2018
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
Matteo
27 Jun 2019
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
login page listen change localstorage changelocalstorage change eventwatch localstorage same windowjavascript observe localstoragehow to listen to value changes in localstoragelisten to local storage changes javascriptchange in local storage event listener ljs listener on change in localstoragelisten for localstorage changesjavascript localstorage change eventjavascript watch for change in localstoragelocalstorage value change eventhow to get local storage changed in javascripthow to listen for localstorage value changesjavascript listen to localstorage changejs on localstorage changewhen storage is changed javascript google chromelocalstorage listen for changeswindow on localstorage changerun function when localstorage item is changedlocalstorage on change javascriptjs listen when storage changeslisten local storage value change event javascriptjs listen for changes in value in localstoragelocalstorage event changejavascript observe localstorage same windowjavascript listen to dom add childrenjavascript how to watch for changes in localstoragemodify localstorage jslisten for localstorage change javascriptlocal storage change listenerlocalstorage change event examplewatch localstorage changesget localstorage when id changesdetect localstorage changelistn to changes in sessionstoragelistyen for local storage changesvue listen listen dom add elementlocalstorage change listenerhandle localstorage changeevent localstorage changehtml listen to storage changejs listen localstorage changeevent to listen localstorage changesjs events on localstorage changejavascript listen localstorage changejs local storage change listenersubscibe to storage chanagesnot able to listen to changes in local storafeupdate the dom on local storage item changewatch for localstorage changereact listen to local storage changelisten to localstorage changesjs localstorage listen item changedjavascript listen for localstorage changejs event on local storage changelocalstorage watch for changesweb listen to localstorage changeslisten to change in local storage javascriptget localstorage change javascript listen to changes in localstoragelisten to localstorage changes angularlistener for localstorage change javascriptjs localstorage on changelisten localstorage changelocal storage listen to updatesjs listen localstorage change