Reputation: 377
Background:
In android Webview:
When user is Online
Page A
is loaded from Website.localStorage('X')
on Page A
.When user is offline
Page B
(saved locally) is displayed.Page B
fetch data from localStorage('X')
and store in localStorage('Y')
.Page B
perform operations on localStorage('Y')
in JavaScript.When user is Online again
localStorage('Y')
and store in localStorage('X')
.Issue
localStorage('X')
value is not passed to localStorage('Y')
& vice-versa.
Looking for:
Ways to pass localStorage
Value from Website to local HTML file & Vice-Versa
Upvotes: 0
Views: 615
Reputation: 14561
You cannot share data across two domains using localStorage
.
One of the methods used to share data across domains is through use of postMessage
API. In addition to the MDN link, you can find some more details here: How do you use window.postMessage across domains?
In your case, you may need to make the following changes:
When user is Online
Page C
is openedPage C
opens Page A in an iframe element.Page A
needs to save any data to localStorage
, it sends the data via postMessage
to the parent page, i.e. Page C
. In turn Page C
can save the data to localStorage.When user is offline
Page B
(saved locally) is displayed.localStorage
stored by Page C
, because both were opened offline.Upvotes: 1