jquery - Listen to localstorage change event -
is there way add change event listener browser localstorage items.
i have standalone app makes changes localstorage want backbone view listen , accordingly perform actions.
i couldn't find on internet except way in jquery:
$(window).bind('storage', function (e) { console.log(e.originalevent.key, e.originalevent.newvalue); });
jquery can bind storage
event (in exact way wrote), there few things must note:
- you must run code behind real ip/domain (you can read more my explanation here)
- the
storage
event fire on every open tab except current tab (which mean - if have 1 open tab, , make change local-storage in tab - will not fire). more information here.
regarding backbone - try this:
var someview = backbone.view.extend({ initialize:function() { $(window).on("storage", this.handlelocalstoragechange) } });
Comments
Post a Comment