最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Download a file via jquery and redirect - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 16

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)

  1. 暂无评论