I am trying to use my JavaScript code in Android WebView. First I enable Javascript and load html with my script.
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/javascript.html");
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setBuiltInZoomControls(true);
After that I load some web page in WebView.
webView.loadUrl("http://www.example.com");
When I try to do this
webView.evaluateJavascript("myJavascript();", null);
I get message :
[INFO:CONSOLE(1)] "Uncaught ReferenceError: myJavascript is not defined"
Function myJavascript
is defined in "javascript.html" in assets. I suppose that is because after load some page JavaScript is no more in WebView. Can I have loaded in same time HTML with my JavaScriptcode and some web page? I want to define JavaScript in HTML.
try this
setDomStorageEnabled(true);
webView.loadUrl("http://www.example.com");
For more information webview settings check out following link
http://developer.android.com/reference/android/webkit/WebSettings.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.