Home > Web Front-end > HTML Tutorial > webview prints the content of html (html js composite)_html/css_WEB-ITnose

webview prints the content of html (html js composite)_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:42:27
Original
1307 people have browsed it

ps: Because my content is filled with html and js, it cannot be printed directly

Follow the following three steps to get it done

1.

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


2.

webView.addJavascriptInterface(new InJavaScriptLocalObj(), "local_obj");
Copy after login


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('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");}
Copy after login




source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template