Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: js to download
07-16-2013, 07:20 PM #1
- Join Date
- Aug 2012
- Thanked 0 Times in 0 Posts
js to download
I have a download section in my website where I will put my documents for user download. I want the user only left mouse click to the link then his browser will prompt the download screen tosave file.
07-16-2013, 08:39 PM #2
<a href="somefile.xxx"> download somefile </a>
But if you don't want the file to be opened *in* the browser (e.g., say it is a PDF file, which would normally just open up right in the browser; or an MS Word file opening in MSIE browser), then you have to alter its HTTP content information, and that means server-side coding. For example, with PHP you could do
(Similar code with other server-side systems.) And then serve up the file in your HTML href link as a PHP file.Code:header('Content-type: application/pdf'); header("Content-Disposition: attachment; filename=\"xxx.pdf\"");
** EXCEPTION **
*IF* the browser is HTML5 compatible, then this should work:
<a href="somefile.pdf" download> download some pdf file </a>
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.