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?
By stating
window.location.href = 'uploads/file.doc';
you show where you store your files. You might of course use .htacess to force the required behaviour for stored files, but this might not always be handful....It is better to create a server side php-file and place this content in it:
This code will return ANY file as a download without showing where you actually store it.
You open this php-file via
window.location.href = 'scripts/this_php_file.php?f=downloaded_file';
See here for a similar post on using jQuery to clear forms: Resetting a multi-stage form with jQuery
You may also be running into an issue where the values are being repopulated by the struts value stack. In other words, you submit your form, do whatever in the action class, but do not clear the related field values in the action class. In this scenario the form would appear to maintain the values you previously submitted. If you are persisting these in some way, just null each field value in your action class after persisting and prior to returning SUCCESS.
Yes, you would have to change the window.location.href to the url of the file you would want to download.
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.
Using jQuery function