【问题标题】:Android WebView : Remove pop-out option in google drive/doc viewerAndroid WebView:删除谷歌驱动器/文档查看器中的弹出选项
【发布时间】:2014-12-31 06:38:07
【问题描述】:

我正在通过将 pdf url 附加到 google doc api 在 WebView 中加载 pdf 文档

http://docs.google.com/gview?embedded=true&url=myurl

PDF 加载正常,但网页显示两个选项 - Zoom-inPop-Out。有没有办法通过发送一些参数来禁用/隐藏弹出选项?任何帮助将不胜感激。提前致谢!

【问题讨论】:

  • 正在寻找同样的东西,但似乎根本没有 google docs viewer 的文档。
  • 是的。似乎是这样。即使我找不到任何文档。

标签: android pdf google-drive-api android-webview google-docs


【解决方案1】:

您可以添加此回调,结果“弹出”按钮将被删除。

@Override
    public void onPageFinished(WebView view, String url) {

        super.onPageFinished(view, url);
        mWebView.loadUrl("javascript:(function() { " +
                "document.querySelector('[role=\"toolbar\"]').remove();})()");
    }

注意:如果您现在想要显示此按钮,请在应用最后一个 javascript 代码后使您的 web 视图可见。

【讨论】:

  • 我发现你的解决方案很有用,然后是一个接受的答案,但你有没有注意到,当进度条运行时,它仍然显示弹出选项,所以任何人都可以点击它......并执行进一步的操作。你有同样的解决方案吗?
【解决方案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'; })()");
        }
    })

【讨论】:

  • 太棒了。非常天才的解决方案
  • 它只是隐藏了选项,但该视图仍然存在。还有其他隐藏视图的选项吗??
  • @SarithaG :我在这个问题上做了很多研究,我认为没有隐藏该视图的选项。我们所能做的就是使用 CSS 代码破解我们可以隐藏该视图。
  • 感谢您的回复..您可以发布该 CSS 代码吗..?
  • @Jaffar 嗨.. 我已经尝试过您的解决方案来达到同样的效果。但我无法隐藏它。我已经在stackoverflow.com/questions/42382984/… 上用代码发布了我的问题。你能否检查一下并建议我任何想法。提前致谢。
【解决方案3】:
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 浏览器中的重定向

快乐编码

【讨论】:

  • 这对我有用。谢谢@Darshan Khatri
【解决方案4】:

这是禁用它的代码:

<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>

【讨论】:

    【解决方案5】:

    严格禁止任何人点击“弹出”

    1. 使用

      从一开始就隐藏 WebView
      webview.setVisibility(View.GONE)
      
    2. 在网页视图内

      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);
              }
          });
      

    简单而有效!干杯

    【讨论】:

      【解决方案6】:

      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"/>
      

      输出:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-28
        • 1970-01-01
        • 2022-01-05
        • 2013-01-15
        • 1970-01-01
        • 1970-01-01
        • 2017-11-06
        相关资源
        最近更新 更多