在浏览器页面中禁用PDF加载[重复]

时间:2022-06-18 05:41:35

This question already has an answer here:

这个问题在这里已有答案:

I've developed a web app (nodewebkit) and I have a link "linked" to a pdf document:

我开发了一个Web应用程序(nodewebkit),我有一个链接“链接”到pdf文档:

<div id="container">
  <a href="path/document.pdf"></a>
</div>

I've noticed that in some computers, when user click on link, browser propose to download the file. In others, instead, browser show pdf inside the page.

我注意到在某些计算机上,当用户点击链接时,浏览器建议下载该文件。在其他情况下,浏览器在页面内显示pdf。

How can I get the same behavior on all browsers? I need the download option!

如何在所有浏览器上获得相同的行为?我需要下载选项!

I suppose that I've to prevent default behaviour:

我想我要防止默认行为:

$('container').on('click', 'a', function(e) {
   e.preventDefault();
   ...
});

1 个解决方案

#1


3  

You could use the HTML5 download attribute like so:

您可以使用HTML5下载属性,如下所示:

  <a href="path/document.pdf" download> Click to download</a>

This opens a "save as" dialog regardless of file type without taking you away from the page.

这将打开一个“另存为”对话框,无论文件类型如何,都不会让您离开页面。

#1


3  

You could use the HTML5 download attribute like so:

您可以使用HTML5下载属性,如下所示:

  <a href="path/document.pdf" download> Click to download</a>

This opens a "save as" dialog regardless of file type without taking you away from the page.

这将打开一个“另存为”对话框,无论文件类型如何,都不会让您离开页面。