【问题标题】:Iframe displaying pdf from download link从下载链接显示 pdf 的 iframe
【发布时间】:2014-09-09 08:14:38
【问题描述】:

我正在编写一个 html 网页,我需要在 iframe 中显示来自下载链接的 pdf,如何跳转下载链接并在不下载文件的情况下显示 pdf?。

对不起,如果我解释错了,简而言之,我需要使用 iframe 在网络上显示仅与他链接的 PDF 的内容是强制下载链接,我测试了您的解决方案,但它不适用于我的目标,有什么想法吗?

感谢您阅读我。

【问题讨论】:

    标签: html pdf iframe hyperlink


    【解决方案1】:

    可以使用javascript加载源码,在页面源码中iframe url是看不到的。例如jQuery:

    <script type="text/javascript">
    $(document).ready(function(e) {
      $('iframe').attr('src','http://www.yourwebsite.com/pdf');
    });
    </script>
    
    <body>
    <iframe src="" />
    </body>
    

    Example here.

    您可以将它与 $.post 结合使用以获取服务器端的值:

    $.post('get-iframe-src.php', function(data) {
      $('iframe').attr('src',data);
    });
    

    您甚至可以将 iframe 本身加载到某些元素,例如:

    $.post('get-iframe.php', function(data) {
      $('#element_id').html(data);
    });
    

    【讨论】:

    • 你是说你不能访问源代码中的pdf源?因为你可以...
    【解决方案2】:

    使用iframe 显示 PDF 并不适用于所有浏览器,因为有些浏览器会尝试下载实际文件。

    你应该看看PDFObjects.

    这就是你将如何使用它:

     <object data="myfile.pdf" type="application/pdf" width="100%" height="100%">
    
      <p>It appears you don't have a PDF plugin for this browser.
      you can <a href="myfile.pdf">click here to
      download the PDF file.</a></p>
    
    
    </object>
    

    您可以将文件的 URL 放入 data 属性中。

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多