How to Read Javascript Variables From WebView on the Android
The Android "WebView" control lets you display a Web page in the user's Android device and manipulate and read the site's content such as JavaScript or HTML content. Android uses the Java language to create apps, and the Eclipse app environment includes an emulator you use to run the programs to test for any bugs. You can use the environment to open the website and review the Web page JavaScript variables.
Instructions
-
-
1
Open the Eclipse Java software and the Android app you want to edit. Double-click the Java source code file that contains the WebView control.
-
2
Load the WebView URL. The following code opens a website page in the Android's viewer:
webView.loadUrl("site.com");
Replace "site.com" with the URL that contains the JavaScript variables.
-
-
3
Load the JavaScript Web settings. JavaScript is disabled by default, so you must enable JavaScript to view the variables. Add the following code to your function:
WebSettings setup = webView.getSettings();
setup.setJavaScriptEnabled(true); -
4
Retrieve the JavaScript variable you want to view. You must call the JavaScript function contained in the Web page to view the variables. Add the following code to retrieve the variables and the variables' values:
webView.loadUrl("javascript:myfunction()");
Replace "myfunction" with the name of your JavaScript function.
-
1