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('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");}立即学习“前端免费学习笔记(深入)”;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号