开发者

Download a file via jquery and redirect

开发者 https://www.devze.com 2023-03-24 09:59 出处:网络
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 s

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

精彩评论

暂无评论...
验证码 换一张
取 消