Android - Do All Webviews In An Activity Share Variables? How Is The Scope In A Webview?
I have a class that draws charts using d3js javascript library. I'm trying to have a global variable to keep track of all the charts drawn, local to my webview, but im loading two
Solution 1:
Each WebView will have it's own JavaScript context and not share variables with any other WebView. If you want to transfer the value of these variables between WebViews then you'll need to write some code, probably something like this:
- Add a JavaScript interface to WebView1 which you can call from JavaScript to get the value of the variable in Java. See http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String)
- Pass the value into WebView2 using loadUrl with a
javascript:
URL.
Hope this helps.
Post a Comment for "Android - Do All Webviews In An Activity Share Variables? How Is The Scope In A Webview?"