I'd like to figure out a simple way using jQuery to trigger a download when a text link is clicked. Also, after click the user is redirected to success page. Can anyone help?
I'd like to figure out a simple way using jQuery to trigger a download when a text link is clicked. Also, after click the user is redirected to success page. Can anyone help?
Share Improve this question asked Aug 1, 2011 at 6:36 Matt LambertMatt Lambert 3,6652 gold badges26 silver badges17 bronze badges1 Answer
Reset to default 16Let's say you have a link to your download page
<a class="downloadLink" href="www.example.com/foo.pdf">Download</a>
In your Javascript:
$(".downloadLink").click(
function(e) {
e.preventDefault();
//open download link in new page
window.open( $(this).attr("href") );
//redirect current page to success page
window.location="www.example.com/success.html";
window.focus();
}
);