I'd like to figure out a simple way using jQuery to trigger a download when a tex开发者_运维知识库t link is clicked. Also, after click the user is redirected to success page. Can anyone help?
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();
}
);
精彩评论