(HTML)下载PDF文件,而不是在点击浏览器时打开它们 [英] (HTML) Download a PDF file instead of opening them in browser when clicked

查看:695
本文介绍了(HTML)下载PDF文件,而不是在点击浏览器时打开它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何下载PDF文件链接而不是在浏览器中打开它们?这是如何完成的HTML? (我假设它是通过JavaScript或其他)完成的。

解决方案

您无法使用HTML做到这一点。这是一个基于服务器的解决方案。您必须流式传输文件,以便浏览器触发保存对话框。



我建议不要这样做。用户如何与PDF交互应该留给用户。

更新(2014):



所以...这个答案仍然有很多downvotes。我认为其中的一部分是,这是4年前的答案,正如Sarim指出的那样,现在 HTML 5 download 属性来处理这个问题。

我同意,并且认为Sarim的答案是好的(如果OP返回,它可能应该是选择的答案)。然而,这个答案仍然是处理这个问题的可靠方法(正如YiğitYener的答案所指出的那样 - 人们很同意)。虽然下载属性已经获得支持,但它仍然很不明显:



http://caniuse.com/#feat=download


I was wondering how to make a PDF file link downloadable instead of opening them in the browser? How is this done in html? (I'd assume it's done via javascript or something).

解决方案

You can't do this with HTML. It's a server-based solution. You have to stream the file so that the browser than triggers the save dialog.

I'd advise not doing this. How a user interacts with a PDF should be left up to the user.

UPDATE (2014):

So...this answer still gets plenty of downvotes. I assume part of that is that this was answered 4 years ago and as Sarim points out, there is now the HTML 5 download attribute that can handle this.

I agree, and think Sarim's answer is good (it probably should be the chosen answer if the OP ever returns). However, this answer is still the reliable way to handle it (as Yiğit Yener's answer points out and--oddly--people agree with). While the download attribute has gained support, it's still spotty:

http://caniuse.com/#feat=download

这篇关于(HTML)下载PDF文件,而不是在点击浏览器时打开它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆