PDA

View Full Version : use instead of right click



vikaspa
12-01-2010, 04:38 PM
Dear All

need your help

I use <a href="a.pdf">download</a> to download a.pdf file

Can I use click to download instead of right click

plsease suggest

thanks in advance

djr33
12-01-2010, 05:36 PM
This is based on the browser. Some browsers (on macs, for example) will automatically download. Others (with the adobe reader plugin, for example) will open it in the browser. There's no way to control this in HTML.

You could send the file using incorrect headers to trick the browser into thinking it's something that it is not, so that it saves the unknown file type rather than trying to open it-- this wouldn't affect the saved file itself, just what the browser does with it. The problem is that this is not a proper way to handle the situation (it's a cheap shortcut and often misused), and it requires controlling how the server handles these files. You could use a serverside language like PHP, but it gets complex. And most importantly, even if it works, some browsers will still ignore it.

You can google "force download (header)" and find more information on methods for this and the problems associated with it.


My recommendation is that you don't try to force it one way or another, especially for PDFs. (In some cases, if the files are large, like videos, it saves bandwidth to have users download them rather than stream them repeatedly, but PDFs aren't big enough to matter, unless you have huge PDF files.)
Instead, know that individuals and individual browsers will handle it in the way that is best for them, and if you personally want it to behave differently you can configure your browser to save PDFs rather than use a plugin, or just uninstall the plugin.


If you must force everyone to save the files, one guaranteed way is to put them in zip files. Browsers can't open these, so the user will need to download it and then unzip and view the file locally. It's extra work, but it will help save bandwidth and forces the user to view it locally. It's not usually worth that much extra work though.


Finally, if you just are worried about it replacing your current page, you can have it open in a new window. <a target="_blank" ... will make it open in a new window by default (or new tab), though that is deprecated (not recommended) in newer versions of HTML. Javascript methods onclick="window.open(this.href);return false;" also work. You could even try a popup. Of course the problem here is that if it doesn't open in a plugin, it will create a new blank window and that is annoying.

Test everything on a few computers to see what the situation is like for everyone. Remember that in some cases users might need to open files in the browser. On an iPhone, for example, you can't save a pdf but you can view it in the browser.


The main point here is that it is user preference, so instead of trying to standardize this for your website, just change your personal settings and that will allow others to deal with it the way they want.