我正在开发一个项目,它将 http 请求发送到 spring boot。作为回应,我收到了带有 PDF 文件的流。我需要在新选项卡中打开此文件,并使用 Chrome PDF 查看器的所有功能,尤其是下载功能。
这是我处理响应并打开包含收到的 PDF 文件的新选项卡的代码:
fetch(options.url, options)
.then(response => {
return response.blob();
})
.then(blob => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = () => {
const data = reader.result
const tab = window.open();
tab.document.write("<html>" +
"<body>" +
"<embed type='application/pdf' " +
"style='position:absolute; left: 0; top: 0;' " +
"width='100%' " +
"height='100%' " +
"src='" + data +"'/>" +
"</body>" +
"</html>")
}
})
But there is a problem after new tab opened: all buttons of Chrome PDF viewer work correctly except for 'download' button.
单击按钮后没有任何反应。
您有解决这个问题的想法吗?
尝试更换const tab = window.open();
with const tab = window.open('about:blank', '_blank', "width=200,height=100");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)