Home  >  Article  >  Web Front-end  >  webview打印html的内容(html+js复合)_html/css_WEB-ITnose

webview打印html的内容(html+js复合)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:42:271228browse

ps:因为我的内容是html+js一起填充的,所以不能直接打印

按照下边三个步骤就搞定了

1. 

final class InJavaScriptLocalObj {	@JavascriptInterface 	   public void showSource(String html) {		Log.d("HTML", html); 		        }		}


2. 

webView.addJavascriptInterface(new InJavaScriptLocalObj(), "local_obj");


3.

webView.setWebViewClient(new WebViewClient() {@Override 	public void onPageFinished(WebView view, String url) { 	  super.onPageFinished(view, url);  // view.loadUrl("javascript:alert(document.getElementsByTagName('html')[0].innerHTML)");  view.loadUrl("javascript:window.local_obj.showSource(''+document.getElementsByTagName('html')[0].innerHTML+'');");}




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn