On Click Download and Redirect to Thank You Page using jQuery


So I ran into a rather interesting need of a client. They wanted to have a link to a downloadable file but also have a redirect to a thank you page. I found that I could add some data to the link that allowed me to write some jQuery and allow the link and thank you page be driven off of the data on that page.

Here is a sample of a link that links directly to a downloadable file but also redirects to the thank you page.

<a href="link/to/file.pdf" class="download-redirect" typage="/thank-you/">Click here to download the document</a>


Here is what I placed in my included JavaScript file. Of course jQuery will have to have already been included.

/* Custom Download/Redirect JS File */

    function(e) { 
        var download_url = jQuery(this).attr("href");
        var typage = jQuery(this).attr("typage");
        window.open( download_url );



Posted on

August 24, 2020

Submit a Comment

Your email address will not be published. Required fields are marked *