0
votes

How do I open PDF on a new tab, target="_blank" alone does not work it still open the pdf in the same tab.

3
show us some code - Hitesh Misro
No code needed, that's just a technical question. - xoxel
A good question to ask is is this an XY problem? So, do you want users to open the PDF and view it or to merely get it without navigating away from a page? If it's the latter, and you've chosen to do that via opening a new tab/window, you should know that there is also the download attribute for a tags in HTML5 you can use. It tells the browser that whatever you're linking should be downloaded, not opened. Thus a user can get the PDF and stay on the page. - VLAZ

3 Answers

2
votes

Method-1 : HTML

<a target="_blank" href="http://your_url_here.html">Link</a>

You can simply do that with setting target="_blank" for an example check this

More Details

Method-2 : Javascript

<a onclick="openInNewTab('Your URL');">Something To Click On</a>

function openInNewTab(url) {
  var win = window.open(url, '_blank');
  win.focus();
}
1
votes

Without your code is hard to tell what's wrong but did a fast test and this worked for me..

<a target="_BLANK" href="pdf/your_pdf.pdf">YOUR PDF</a>
1
votes

You have to know: "_Blank" is not working as a "new tab" on every browser.

To do that, you have to use js like this:

<a href="..." onclick="javascript:windows.open('link', [options]);">Lnk</a>

(it will work on any browser, "_blank" will not)

EDIT: Of course, here the "link" in window.open will be the path to where your PDF file is stored.

EDIT2 (thanks to vlaz): Yep, it will work on any browser if JS is enabled, if he his not it will not.