I hate when sites complicate download so much and use hacks instead of a good old link.
Dead simple version:
<a href="file.zip">Start automatic download!</a>
It works! In every browser!
If you want to download a file that is usually displayed inline (such as an image) then HTML5 has a download
attribute that forces download of the file. It also allows you to override filename (although there is a better way to do it):
<a href="report-generator.php" download="result.xls">Download</a>
Version with a "thanks" page:
If you want to display "thanks" after download, then use:
<a href="file.zip"
onclick="if (event.button==0)
setTimeout(function(){document.body.innerHTML='thanks!'},500)">
Start automatic download!
</a>
Function in that setTimeout
might be more advanced and e.g. download full page via AJAX (but don't navigate away from the page — don't touch window.location
or activate other links).
The point is that link to download is real, can be copied, dragged, intercepted by download accelerators, gets :visited
color, doesn't re-download if page is left open after browser restart, etc.
That's what I use for ImageOptim