Download File Using jQuery
Here's a nice article that shows many ways of hiding files from search engines:
http://antezeta.com/news/avoid-search-engine-indexing
JavaScript isn't a good way not to index a page; it won't prevent users from linking directly to your files (and thus revealing it to crawlers), and as Rob mentioned, wouldn't work for all users.
An easy fix is to add the rel="nofollow"
attribute, though again, it's not complete without robots.txt.
<a href="uploads/file.doc" rel="nofollow">Download Here</a>
Yes, you would have to change the window.location.href to the url of the file you would want to download.
window.location.href = 'http://www.com/path/to/file';
If you don't want search engines to index certain files, you can use robots.txt to tell web spiders not to access certain parts of your website.
If you rely only on javascript, then some users who browse without it won't be able to click your links.
I might suggest this, as a more gracefully degrading solution, using preventDefault
:
$('a').click(function(e) {
e.preventDefault(); //stop the browser from following
window.location.href = 'uploads/file.doc';
});
<a href="no-script.html">Download now!</a>
Even if there's no Javascript, at least this way the user will get some feedback.