android - JavaScript: How to reload page when localstorage changes? -


i'm making series of javascript pages share information via localstorage. works fine, when change parameter in 1 of pages , move different one, need reload manually ctrlr changes become effective. succeeded @ doing refreshing automatic using onblur, but, alas, such function stops working when upload scripts android (the final destination of these scripts becoming android app).

so i'm trying use addeventlistener storage event, nothing happens, still have refreshing manually. i've read lots of web sites , gone through lot of examples still don't it. here relevant code:

window.addeventlistener("storage", handler);  function handler() {     location.reload(); } 

let me share more i'm trying do: have series of html pages, each of them form make calculation diet plan. example: first 1 asks body info , gives basal calory intake.

a second page takes basal calory intake number, stored using localstorage, shows in screen, , asks in form introduce daily calory target; 2 numbers, calculates how long take lose 1 kilo.

if go first page , enter different body measures, generating different output, , revisit page 2, want find basal calory number there automatically refreshed. succeeded @ doing in computer using onblur , onfocus:

window.onblur= function() {window.onfocus= function () {location.reload(true)}}; 

this reloads page of tab you're landing in every time js detects you've changed 1 tab another, notwithstanding if localstorage data has been changed or not - 'just in case' approach.

the problem when upload these pages android, refreshing stops stops working (and in android cannot ctrl+r force it). apparently android not consider different pages tabs; explain onblur , onfocus not working.

that's why i'm trying localstorage approach: "if localstorage has changed, (i.e., has been changing values in other pages), refresh screen on current page (so new values show up)".

i know localstorage events work in browser because this demo works. cannot make code work in scripts.

i hope having explained myself more time (please bear me, first post...)

the storage handler called when changes in tab not in current tab.
override setitem method.

!function() {     var setitem = storage.prototype.setitem;      storage.prototype.setitem = function() {        setitem.apply(this, arguments);        location.reload();     }; }(); 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -