问题
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.
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.
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.
All the best! T.
回答1:
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.
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
来源:https://stackoverflow.com/questions/8429505/how-can-i-force-a-save-as-option-when-the-user-clicks-a-link