Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

listen to localstorage changes

window.addEventListener('storage', () => {
  // When local storage changes, dump the list to
  // the console.
  console.log(JSON.parse(window.localStorage.getItem('sampleList')));
});
Comment

js listen localstorage change

var originalSetItem = localStorage.setItem;

localStorage.setItem = function(key, value) {
  var event = new Event('itemInserted');

  event.value = value; // Optional..
  event.key = key; // Optional..

  document.dispatchEvent(event);

  originalSetItem.apply(this, arguments);
};

var localStorageSetHandler = function(e) {
  alert('localStorage.set("' + e.key + '", "' + e.value + '") was called');
};

document.addEventListener("itemInserted", localStorageSetHandler, false);

localStorage.setItem('foo', 'bar'); // Pops an alert
Comment

listen to localstorage changes

var originalSetItem = localStorage.setItem; 
localStorage.setItem = function(){
    document.createEvent('Event').initEvent('itemInserted', true, true);
    originalSetItem.apply(this, arguments);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript fetch get data from promise 
Javascript :: javascript function length 
Javascript :: array join method 
Javascript :: javascript global object 
Javascript :: javascript foreach url parameter 
Javascript :: knexjs whereIn 
Javascript :: match ids from 2 arrays in javascript asynchronous programming 
Javascript :: javascript flatten array of arrays 
Javascript :: disable button in angular 
Javascript :: typescript react handle change 
Javascript :: vue add external script 
Javascript :: Environment key "jest/globals" is unknown - react 
Javascript :: Example: Export a Variable in Node 
Javascript :: classlist 
Javascript :: change the value in checkbox by button react 
Javascript :: how to dynamic title in nuxt 
Javascript :: uml diagram javascript 
Javascript :: immediately invoked function expression 
Javascript :: mdbootstrap react 
Javascript :: how to import a json string from a file in typescript 
Javascript :: ng-if variable is undefined 
Javascript :: javascript design patterns pdf 
Javascript :: js connect to websocket 
Javascript :: javascript lowest number 
Javascript :: list keys json python 
Javascript :: js add function to array 
Javascript :: what is redis used for 
Javascript :: jquery get all classes of a div 
Javascript :: tooltip in chakra ui 
Javascript :: index of an element 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =