【问题标题】:How to disable pop-out option in pdf viewer with google doc iframe?如何使用 google doc iframe 在 pdf 查看器中禁用弹出选项?
【发布时间】:2015-03-30 14:59:50
【问题描述】:

我正在使用以下代码使用带有 iframe 的 google 显示 pdf。它工作正常。 但我想禁用我网页上放大选项旁边右上角的“弹出”选项(单击在新选项卡中使用谷歌文档打开我的 pdf)。有可能吗?

目前我正在使用以下代码 -

<iframe src="http://docs.google.com/gview?url=http://example.com/files/myfile.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0">

【问题讨论】:

  • 你找到解决办法了吗??

标签: html iframe google-docs google-document-viewer


【解决方案1】:

可以使用sandbox 来阻止popupiframe 内部工作

<iframe 
    sandbox="allow-scripts allow-same-origin"
/>

allow-scripts: 在 iframe 中运行 javascript。
allow-same-origin: 允许从谷歌查看器加载文件。
如果没有allow-popups,当用户点击pop-out 图标时不会发生任何事情。

来源:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe

【讨论】:

    【解决方案2】:

    在您的页面上运行此 javascript(带有 jQ​​uery 的示例)(我假设所有客户端的类都相同)

    $('.ndfHFb-c4YZDc-Wrql6b').remove();
    

    【讨论】:

    • 您确定此代码适用于第三方 iFrame 吗?
    • @RavinderKumar 不,它没有。
    • 班级不一样,每次都是随机的。它也不适用于第三方 iframe。
    【解决方案3】:

    以下解决方案对于删除预览按钮很有用。添加您的 iframe 的此代码 onload 功能。它在 iframe 加载后应用。

    var head = $("#iframe").contents().find("head");
    var css = '<style type="text/css">' +
              '.ndfHFb-c4YZDc-Wrql6b{display:none}; ' +
              '</style>';
    $(head).append(css);
    

    【讨论】:

    • 它对我有用。也许你的情况类名不同,你改变一个头的类名,然后再试一次。
    猜你喜欢
    • 2019-12-25
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    • 2011-01-16
    • 1970-01-01
    • 2015-02-25
    相关资源
    最近更新 更多