Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a new tab and download a PDF at the sametime

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?

like image 766
Sam Avatar asked Jun 03 '15 15:06

Sam


People also ask

How do I get a PDF to open in a new tab without downloading?

In the Chrome browser, select the three vertical dots in the upper-right corner. Choose Settings > Advanced > Privacy and security. Select Site Settings > PDF documents. Use the toggle switch next to Download PDF files instead of automatically opening them in Chrome to turn the feature on and off.

How do I get a PDF to open in a new tab in HTML?

You just need an anchor ( <a> ) element with three important attributes: The href attribute set to the URL of the page you want to link to. The target attribute set to _blank , which tells the browser to open the link in a new tab/window, depending on the browser's settings.


1 Answers

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

window.open("https://www.workbooks.com/case-studies",'_blank');
like image 95
m4lt3 Avatar answered Sep 28 '22 02:09

m4lt3