英文:
Download pdf instead of opening in browser
问题
我正在尝试在我的 JavaScript 中下载一个 tiff 和 pdf 文件,但这只适用于 tiff 文件。pdf 文件会在浏览器中打开,改变我的用户界面的视图,这是不希望的。由于我只能在该环境中使用 IE 9,所以我被困在这里。
<a href="<%=fileName%>" download="<%=fileName%>"><%=fileName%</a>
英文:
I am trying to download a tiff and pdf in my javascript but this only works for tiff files. The pdf ones open in the browser changing the view of my UI which is not desired. I am stuck with using IE 9 as that is only browser I can use in that environment.
<a href="<%=fileName%>" download="<%=fileName%>"><%=fileName%></a>
答案1
得分: 1
只需将 target="_blank"
属性添加到锚 <a>
元素中:
<a href="<%=fileName%>" download="<%=fileName%>" target="_blank"><%=fileName%></a>
这将在新标签页/窗口中打开 PDF(如果这是默认浏览器行为)。您不会离开您的网站。如果不会自动下载,您现在可以从标签页中保存 PDF。
英文:
Simply add the target="_blank"
attribute to the anchor <a>
element:
<a href="<%=fileName%>" download="<%=fileName%>" target="_blank"><%=fileName%></a>
This will open the PDF in a new tab/window (if that is the default browser behavior). You will not navigate away from your website. You can now save the PDF from the tab, if it doesn't automatically get downloaded.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论