最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Android's Webview cannot handle javascript? - Stack Overflow

programmeradmin1浏览0评论

My android application displays webpages(i used webview for it). .but javascript onthe wepage is not running in a webview .If i visit the same webpage through the Browser,javascript is running . How to run javascript in an application(using a webview)?

My android application displays webpages(i used webview for it). .but javascript onthe wepage is not running in a webview .If i visit the same webpage through the Browser,javascript is running . How to run javascript in an application(using a webview)?

Share Improve this question asked Aug 10, 2010 at 15:47 rimporimpo 611 silver badge2 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 13

Enable Javascript! :

WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

WebView : setJavaScriptEnabled

From the Android documentation:

"By default, a WebView provides no browser-like widgets, does not enable JavaScript and web page errors are ignored. If your goal is only to display some HTML as a part of your UI, this is probably fine; the user won't need to interact with the web page beyond reading it, and the web page won't need to interact with the user. If you actually want a full-blown web browser, then you probably want to invoke the Browser application with a URL Intent rather than show it with a WebView.

...

However, you can modify the WebSettings, such as enabling JavaScript with setJavaScriptEnabled()."

For Easy way you can use WebChromeClient, see in this video tutorial.

If you want more control with js, you can use method with addJavascriptInterface, but you must create your html-page for this method (). Look at this sample.

发布评论

评论列表(0)

  1. 暂无评论