【问题标题】:PDF gets stuck when opening through iframe using window.open()使用 window.open() 通过 iframe 打开 PDF 时卡住
【发布时间】:2018-08-28 13:16:40
【问题描述】:

我正在尝试在新选项卡中打开作为 base64 格式字符串接收的 PDF。它在没有任何内容的新窗口中打开,但是当我在页面上执行“检查元素”时,我得到的 PDF 非常好。

这是我的代码 -

var pdfWindow = window.open("about:blank", "_blank");
pdfWindow.document.write("<iframe width='100%' height='100%' src='data:application/pdf;base64, " + encodeURI(payload)+"'></iframe>");

另外,我想在新选项卡中打开 PDF,而不是在新窗口中。在新窗口中打开时,PDF 可以正常打开。

要在新窗口中打开,我使用此代码 -

let pdfWindow = window.open("", '_blank', 'dependent=yes,locationbar=no,scrollbars=no,menubar=no,resizable,screenX=50,screenY=50,width=850,height=800')
pdfWindow.document.write("<iframe width='100%' height='100%' src='data:application/pdf;base64, " + encodeURI(payload)+"'></iframe>");

【问题讨论】:

    标签: javascript pdf iframe window.open


    【解决方案1】:

    这是一个老问题,但可能对其他人有帮助: 问题在于 iframe 宽度和高度标签。不要使用百分比,而是使用定义的像素。这将解决问题。

    <iframe width='600px' height='600px' ...> </iframe>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-18
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      相关资源
      最近更新 更多