admin管理员组

文章数量:1317906

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?

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?

Share Improve this question asked Jun 18, 2014 at 7:15 AtanuCSEAtanuCSE 8,94015 gold badges79 silver badges115 bronze badges 10
  • localStorage is limited to the same domain policy. – Jeremy J Starcher Commented Jun 18, 2014 at 8:06
  • it wont work like that, it's like youd want to have a cookie in one card of browser available in another card. inappbrowser is another 'instance' of browser, independent from phonegap webview, you can at most inject some script from phonegap into inappbrowser but cant do it in the opposite way. You can do some POST from the website your opening in inappbrowser and then GET it in your app. – Marcin Mikołajczyk Commented Jun 18, 2014 at 8:09
  • @JeremyJStarcher ah ok, got it. Thanks. So I need to drop the idea with localStorage and start finding something new. – AtanuCSE Commented Jun 18, 2014 at 8:29
  • I've not played enough with cordova/phonegap to remend another solution, but it sounds like the sort of thing that would have been discussed here on StackOverflow. Might want to search it. – Jeremy J Starcher Commented Jun 18, 2014 at 8:31
  • @MarcinMikołajczyk Okay! got that. But did you mean $_POST $_GET?? I read somewhere that php function can't work with phonegap without remote server. Can you tell me an example how can interact with my local pages inside phonegap to municate using POST GET! – AtanuCSE Commented Jun 18, 2014 at 8:33
 |  Show 5 more ments

2 Answers 2

Reset to default 4

So as Jeremy J Starcher & Marcin Mikołajczyk mented, 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.

Take a look at this nice blog post, where munication between main view and InAppBrowser is discussed:

http://blogs.telerik./appbuilder/posts/13-12-23/cross-window-munication-with-cordova%27s-inappbrowser

Basically, it's done by injecting JavaScript into InAppBrowser for evaluation and catching the result.

本文标签: javascriptlocalStorage value set from inAppBrowser not showing outsidecordovaStack Overflow