Reputation: 182
I have a ViewController which has multiple UIWebViews
. I am using localstorage.setItem
to store some variables. But the problem is that these variables are accessible only within the UIWebViews
in which has been set. If i am trying to get( localstorage.getitem) the variable of other UIWebViews
it's giving null value .
WebView1=====>>>>localStorage.setItem("var1","val");
WebView2=====>>>>alert(localstorage.getItem("var1"));
===>>is null
Upvotes: 1
Views: 1615
Reputation: 6393
Sorry, but that's just how the framework is designed: every UIWebView
is it's own instance, isolated from other instances in the same app (just like there is no built-in pop-up or tab functionality).
If there is absolute no other way around it, you could make the web views Cordova WebView's and programatically arrange for some way to transfer data between them via the native layer (there's also alternatives, like WebViewJavascriptBridge that accomplishes the same thing).
Maybe you could even get by just by injecting the data needed using stringByEvaluatingJavaScriptFromString
into a known data structure beforehand. But having the Javascript in a UIWebView
call the native side is a well known difficult-to-do thing that can only be solved by using bridging solutions like i mentioned in the second paragraph.
Upvotes: 2