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});
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
1var originalSetItem = localStorage.setItem;
2localStorage.setItem = function(){
3 document.createEvent('Event').initEvent('itemInserted', true, true);
4 originalSetItem.apply(this, arguments);
5}
6