提示用户下载PDF文件,而不是开放 [英] Prompt user to download PDF file instead of opening
本文介绍了提示用户下载PDF文件,而不是开放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目网站,如果我点击一个链接时,PDF在一个新的或父窗口中打开。好吧,我希望有一个框出现,提示用户下载该文件,而不是打开它。
In my project site, if I click on a link, the PDF opens in a new or parent window. Well I want a box to appear that prompts the user to download the file instead of opening it.
有谁知道一个简单的JavaScript onClick事件,将做到这一点,在所有浏览器,使用默认设置的?
Does anyone know of a simple JavaScript onClick event that will do this, in all browsers, with default settings?
我的服务器是基于PHP的。
My server is PHP based.
推荐答案
由于您使用PHP你的编辑状态,在这里是如何做到同样在PHP中:
Since your edit states that you're using PHP, here's how to do the same in PHP:
<?php
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile('original.pdf');
?>
这篇关于提示用户下载PDF文件,而不是开放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文