我通过将pdf网址附加到Google doc api
来加载WebView中的pdf文档 http://docs.google.com/gview?embedded=true&url=myurl
Pdf加载得很好,但网页显示两个选项 - Zoom-in
和Pop-Out
。有没有办法通过发送一些参数来禁用/隐藏弹出选项?任何帮助将不胜感激。谢谢!
答案 0 :(得分:6)
您可以在结果中添加此回调"弹出"按钮将被删除。
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mWebView.loadUrl("javascript:(function() { " +
"document.querySelector('[role=\"toolbar\"]').remove();})()");
}
注意:如果您现在想要显示此按钮,请在应用上一个javascript代码后显示您的网络视图。
答案 1 :(得分:4)
mWebview = (WebView) findViewById(R.id.your_web_view_id);
//do the javascript enable to your webview
mWebview .getSettings().setJavaScriptEnabled(true);
//set the WebViewClient
mWebview .setWebViewClient(new WebViewClient() {
//add this line to Hide pop-out tool bar of pdfview in pagLoadFinish
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mWebview .loadUrl("javascript:(function() {document.querySelector('[class=\"ndfHFb-c4YZDc-Wrql6b\"]').remove();})()")
}
})
这将删除弹出工具栏,即chrome浏览器中的重定向
快乐编码
答案 2 :(得分:2)
//initialze WebView
webview = (WebView) findViewById(R.id.fullscree_webview);
//set the javascript enable to your webview
webview.getSettings().setJavaScriptEnabled(true);
//set the WebViewClient
webview.setWebViewClient(new WebViewClient() {
//once the page is loaded get the html element by class or id and through javascript hide it.
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webview.loadUrl("javascript:(function() { " +
"document.getElementsByClassName('ndfHFb-c4YZDc-GSQQnc-LgbsSe ndfHFb-c4YZDc-to915-LgbsSe VIpgJd-TzA9Ye-eEGnhe ndfHFb-c4YZDc-LgbsSe')[0].style.display='none'; })()");
}
})
答案 3 :(得分:0)
以下是禁用该代码的代码:
<div style="width: 640px; height: 480px; position: relative;">
<iframe src="https://drive.google.com/file/d/0ByzS..." width="640" height="480"
frameborder="0" scrolling="no" seamless="" allowfullscreen="allowfullscreen"></iframe>
<div style="width: 80px; height: 80px; position: absolute; opacity: 0; right: 0px; top: 0px;"></div>
</div>
答案 4 :(得分:0)
严格禁止任何人点击“弹出”
使用
从一开始就使WebView保持隐藏状态webview.setVisibility(View.GONE)
在网络视图内
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webView.loadUrl("javascript:(function() { " +
"document.querySelector('[role=\"toolbar\"]').remove();})()");
webView.setVisibility(View.VISIBLE);
}
});
简单却有效!干杯
答案 5 :(得分:0)
100% 工作解决方案,我正在使用以下答案
binding!!.webView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
if(url.contains("https")){ // idea1 : back button to exit!
// finish()
}
return true
}
override fun onPageFinished(view: WebView, url: String) {
// idea 2: to hide button icon & background
binding!!.webView.loadUrl("javascript:(function() { " +
"document.getElementsByClassName('ndfHFb-c4YZDc-GSQQnc-LgbsSe ndfHFb-c4YZDc-to915-LgbsSe VIpgJd-TzA9Ye-eEGnhe ndfHFb-c4YZDc-LgbsSe')[0].style.display='none'; " +
"document.getElementsByClassName('ndfHFb-c4YZDc-Wrql6b')[0].setAttribute('style','width:0px');})()")
}
}
xml:想法 3
<WebView
android:layout_marginStart="-30dp"
android:layout_marginEnd="-30dp"
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>