javascript - 带有 PDF 的新标签 - 下载按钮在 Chrome 上不起作用
问题描述
当用户点击一个按钮时,我向我的服务器发送一个请求,它发回一个 pdf base64。
然后我在新选项卡中打开它,但是Chrome预览中的下载按钮不起作用,当我单击它时没有任何操作。它在 Firefox 上运行良好。
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
解决方案
推荐阅读
- r - 循环特定列数据并将结果添加为 R 中的新列
- r - 在 r 中填充一个 4-D 数组
- javascript - 专注于 v-for 问题中的 textarea
- python - sqlite3什么时候回滚python中的事务,什么时候不回滚?
- c# - Unity2D:修复库存冲突
- java - Android:如何使用 Java 在文本视图中显示动态 HTML 字符串
- image - Coredata 图像转换 swiftUI
- c++ - 触发 Embarcadero 10.2.3 Erreur ilink32
- python - 如何从嵌套列表中删除小于给定长度的条目
- mysql - Laravel 登录超时