Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  58] [ 3]  / answers: 1 / hits: 23185  / 13 Years ago, mon, august 1, 2011, 12:00:00

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?


More From » jquery

 Answers
26

Let'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();
}
);

[#90892] Friday, July 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gonzaloulyssess

Total Points: 225
Total Questions: 114
Total Answers: 112

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;