Use window.open to a tab in the background (not switch focus)

I’m using the following code to open a new tab on click of a PDF download.

The problem is the new tab becomes the main tab often before the PDF loads.

How can I make the view stay on the current window (PDF) and open the new tab but not switch to it?

Note: In Chrome and Opera they understand the HTML5 download tag so the PDF simply downloads and the current window redirects – All good! So this is only a problem on IE & Firefox.

<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" onclick="casestudiesopen()" download><strong>Click here to download your eBook</strong></a></h2>

<script>
function casestudiesopen() {
    window.open("http://www.workbooks.com/case-studies");
}
</script>


Source: html5

Leave a Reply