如何强制“另存为”用户单击链接时的选项 [英] How can I force a "save as" option when the user clicks a link

查看:98
本文介绍了如何强制“另存为”用户单击链接时的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有一个PDF链接,我想知道是否可以随时询问用户是否要下载PDF或在新窗口中打开它。这可能吗?我意识到人们不希望PDF自动下载,但是2个链接或一个选项会很棒。

I have a link to a PDF on my web page and I want to know if it's possible to always ask the user if they want to download the PDF or open it in a new window. Is this possible? I realise that people would not want the PDF to automatically download, but 2 links or an option would be great.

互联网上有很多关于这方面的文档。有些人甚至说我必须要PHP,这在我使用的服务器上是不可能的。

There is quite a lot of documentation about this on the internet, some even saying I'd have to have PHP and this is not possible on the server I use.

我需要一个javascript,jQuery解决方案或替代建议。我不知道多少。

I need a javascript, jQuery solution or alternative suggestion. Not asking for much I know.

非常感谢您阅读本文,我希望这是有道理的。

Thanks very much for reading this and I hope it makes sense.

祝一切顺利!
T。

All the best! T.

推荐答案

可以这样做,但不能在客户端javascript中完成。如果您有一个服务器端脚本来提供文件,它可以发送内容处理:附件标头以及响应。这将在浏览器中触发另存为对话框。

It can be done, but not in clientside javascript. If you have a server side script that feeds the file, it can send a Content-Disposition: attachment header along with the response. This will trigger a save as dialog in the browser.

如果它们是静态文件,您还可以更改服务器的配置。对于Apache,请使用 FilesMatch 指令。这里有一个很好的PDF文件示例:

If they are static files, you can also change the configuration of your server. For Apache use the FilesMatch directive. There's a nice example for PDF files here:

http://www.thingy-ma-jig.co.uk/comment/7045

这篇关于如何强制“另存为”用户单击链接时的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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