2011-04-15 78 views

回答

8

您可以在webView中注入一個javascript並獲取html元素。檢查下面的代碼...

class MyJavaScriptInterface { 
    @SuppressWarnings("unused") 
    @JavascriptInterface 
    public void showHTML(final String html) { 
     //HTML content of the page 
    } 
} 
mWebView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT"); 
mWebView.loadUrl("javascript:window.HTMLOUT.showHTML('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');"); 
+0

該代碼已經爲我工作:)謝謝 – Android 2011-05-05 08:09:37

+0

not worked.it完成()我的activity.why? – 2011-11-20 10:27:14

+0

[INFO:CONSOLE(1)]「Uncaught TypeError:window.HTMLOUT.showHTML is not a function」,source:(1) – 2017-02-04 12:04:02