android代码中webview如何调用JavaScript?
2013-07-19
展开全部
mWebView.setWebChromeClient(new MyWebChromeClient()); mWebView.addJavascriptInterface(new Object(){ /** * This is not called on the UI thread. Post a runnable to invoke * loadUrl on the UI thread. */ public void clickOnAndroid() { mHandler.post(new Runnable() { public void run() { mWebView.loadUrl("javascript:wave()"); } }); } }, "demo"); 同理,在html中必须有一个名为demo的对象调用clickOnAndroid()方法。 /** * Provides a hook for calling "alert" from javascript. Useful for * debugging your javascript. */ final class MyWebChromeClient extends WebChromeClient { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { result.confirm(); return super.onJsAlert(view, url, message, result); } }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询