How can I prompt a download for a user when they click a link.
For example, instead of:
<a href="uploads/file.doc">Download Here</a>
I could use:
<a href="#">Download Here</a>
$('a').click... //Some jquery to download the file
This way, Google does not index my HREF's and private files.
Can this be done with jQuery, if so, how? Or should this be done with PHP or something instead?
Hidden iframes can help
Here's a nice article that shows many ways of hiding files from search engines:
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.I suggest you use the mousedown event, which is called BEFORE the click event. That way, the browser handles the click event naturally, which avoids any code weirdness:
I might suggest this, as a more gracefully degrading solution, using
preventDefault
:Even if there's no Javascript, at least this way the user will get some feedback.