Open a new tab and download a PDF at the sametime

14,915

You should do it this way (during the onClick event):

window.open("https://www.workbooks.com/case-studies",'_blank');
Share:
14,915
Sam
Author by

Sam

Updated on June 14, 2022

Comments

  • Sam
    Sam almost 2 years

    On clicking a PDF download link, I'd like the pdf to be displayed in that same tab and in a second tab the page /case-studies to load.

    Is this possible?

    Currently I've got:

    <h2 style="text-align: center;"><a href="http://cdn2.hubspot.net/hub/155045/file-847580737-pdf/Stepping_into_a_new_age_of_marketing_with_CRM_FINAL_APPROVED.pdf" id="pdflink" target="_blank" download=""><strong>Click here to download your eBook</strong></a></h2>
    <script type="text/javascript">// <![CDATA[
    document.getElementById("pdflink").onclick = function () {
            location.href = "https://www.workbooks.com/case-studies";
        };
    // ]]></script>
    

    However this opens the redirect in a second tab but as the main window confusing the visitor (as if on IE or FF) they don't release the PDF has opened in the first tab.

    Any advice?

  • SidOfc
    SidOfc almost 9 years
    @OP - add it before the location.href tho - otherwise you'll redirect before the new target is set ;)
  • Sam
    Sam almost 9 years
    Thanks please confirm what you mean @SidneyLiebrand