首页 > 解决方案 > 带有 PDF 的新标签 - 下载按钮在 Chrome 上不起作用

问题描述

当用户点击一个按钮时,我向我的服务器发送一个请求,它发回一个 pdf base64。

然后我在新选项卡中打开它,但是Chrome预览中的下载按钮不起作用,当我单击它时没有任何操作。它在 Firefox 上运行良好。

Chrome预览下载按钮:

Chrome 预览下载按钮

定义变量iframeHtml

let iframeHtml = `<iframe
    id="ManualFrame"
    frameborder="0"
    style="border:0; overflow: hidden; margin: 0; height: 100%"
    allowfullscreen>
</iframe>

<script>
setManualFrame();

function setManualFrame() {
  document.getElementById('ManualFrame').setAttribute('height', screen.height);
  document.getElementById('ManualFrame').setAttribute('width', screen.width);
  document.getElementById('ManualFrame').setAttribute('src', "data:application/pdf;base64,${pdfBase64}");
}
</script>`;

然后在新选项卡中打开它:

let newWindow = window.open();
newWindow.document.write(iframeHtml);

我测试过的 Chrome 版本:
版本:67.0.3396.79 (Official Build) (64-bit)
版本:66.0.3359.181 (Official Build) 32 bits

标签: javascriptgoogle-chromepdfdownloadbase64

解决方案


推荐阅读