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 reduce method stack overflow 
Javascript :: find the sum of an attribute in sequelize 
Javascript :: nextjs starter template with auth 
Javascript :: javascript destructing 
Javascript :: browserrouter invalid hook call 
Javascript :: react table with styles 
Javascript :: how to change data value in jquery 
Javascript :: invisible recaptcha google 
Javascript :: concat keys json 
Javascript :: recordrtc 
Javascript :: uselayouteffect 
Javascript :: mongoose max record 
Javascript :: array within array javascript 
Javascript :: how to print json.stringify of nested objects 
Javascript :: apexcharts bar onclick index 
Javascript :: javascript regex insert string 
Javascript :: Number of trailing zeros of N! 
Javascript :: js for await 
Javascript :: javascript struct 
Javascript :: vuetify use selected value 
Javascript :: max value in an array 
Javascript :: Use the parseInt Function 
Javascript :: angular 14 new features 
Javascript :: how to compile javascript 
Javascript :: axios 
Javascript :: big.js 
Javascript :: javascript loop aray 
Javascript :: javascript promise with ajax 
Javascript :: base64 to base64url 
Javascript :: string in js 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =