Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localStorage value set from inAppBrowser not showing outside - cordova

I'm setting up localStorage from inAppBrowser view. Suppose inside the inAppBrowser view I've set

localStorage.setItem("page","10");

Inside inAppBrowser I want to check if the value is set , so I checked with

alert(localStorage.getItem("page"));

It's showing 10. Now I closed the inAppBrowser view and back to my main view. Then again I am giving

 alert(localStorage.getItem("page"));

to check the value in exit event listener. It's showing null or different past value but not 10. Can you please tell me what's wrong?????????

I've also tried with window.localStorage.setItem("page","10");

Basically I wanted to get a value from the inAppBrowser view. I tried the setInterval and executeScript example, but there is a problem in that example. When you do some heavy work inside inAppBrowser that consumes lot of memory, previous activity/webpage gets killed or hanged. Thus that is not efficient. Is there any simple way to work with localStorage and inAppBrowser OR to get get a value from inAppBrowser to main page?

like image 451
AtanuCSE Avatar asked Jan 30 '26 15:01

AtanuCSE


1 Answers

So as Jeremy J Starcher & Marcin Mikołajczyk commented, it's not possible. It's because of the same domain policy and inAppBrowser is a new instance which doesn't allow the previous webview to access it.

Solution is to send back the required data in main view or parent webview and then put them in localStorage.

like image 180
AtanuCSE Avatar answered Feb 02 '26 06:02

AtanuCSE