MultiWizard
MultiWizard

Reputation: 739

Opening a new tab to read a PDF file

I am probably missing something simple here, however i will ask anyway. I have made a link to open up a PDF file, however it opens up in the current tab rather than a new one. What code shall i use in HTML to open a new tab to read the PDF file.

<div class="footer_box_content">
    <div class="cleaner_h10"></div>
    <p>Many  thanks  to  everyone  who cleared snow and ice during the cold spell in February.
    Should Arctic conditions return, each block has a shovel and a jar of rock salt  to  clear  the  steps. 
    Please click more to read the full newsletter.</p>
    <div class="button_01"><a href="newsletter_01.pdf">Read more</a></div>
</div>

Upvotes: 57

Views: 324028

Answers (9)

Chris
Chris

Reputation: 3795

<a href="newsletter_01.pdf" target="_blank">Read more</a>

Target _blank will force the browser to open it in a new tab or window (depending on user browser settings).

Upvotes: 67

Hasan
Hasan

Reputation: 29

Yes, someone has already mentioned that we can force the browser to open pdf file in new tab by using target, but depending on user's browser setting it may force to download instead of opening and I see most of the browser's settings are like so in default.

The easiest way I found is, using Google Drive. We can upload the document in drive and change the setting that anyone with the link can view the doc. Use that link like below:

<a href="https://drive.google.com/file/d/1yQHmS" target="_blank">

When we click the link, the doc will open in the new tab from drive.

Upvotes: -1

Diogo Moreira
Diogo Moreira

Reputation: 1082

Just use target on your tag <a>

<a href="newsletter_01.pdf" target="_blank">Read more</a>

The target attribute specifies where to open the link. Using "_blank" will make your browser to open a new window/tab.

Upvotes: 2

JEWEL JACOB
JEWEL JACOB

Reputation: 584

An observation, _blank alone will not make sure the file is opened in a new tab. The response header for the file request should have Content-Type : application/pdf.

Try this link, it will open the file in new tab as the server provide required headers.

Same is the case for other file types also. For ex: video files get request should have proper Content-Type like video/mp4.

Upvotes: 7

Fastersixth
Fastersixth

Reputation: 123

On Chrome this has proven to work well for me.

<a href="newsletter_01.pdf" target="_new">Read more</a>

Upvotes: 0

Chuck Le Butt
Chuck Le Butt

Reputation: 48758

As everyone else has pointed out, this can work:

<a href="newsletter_01.pdf" target="_blank">Read more</a> 

But what nobody has pointed out is that it's not guaranteed to work.

There is no way to force a user's browser to open a PDF file in a new tab. Depending on the user's browser settings, even with target="_blank" the browser may react the following ways:

  1. Ask for action
  2. Open it in Adobe Acrobat
  3. Simply download the file directly to their computer

Take a look at Firefox's settings, for example:

enter image description here

Chrome has a similar setting:

enter image description here

If the user has chosen to "Save File" in their browsers settings when encountering a PDF, there is no way you can override it.

Upvotes: 60

Nishanth K Kumar
Nishanth K Kumar

Reputation: 1

Try this, it worked for me.

<td><a href="Docs/Chapter 1_ORG.pdf" target="pdf-frame">Chapter-1 Organizational</a></td>

Upvotes: -3

Nick
Nick

Reputation: 4212

You have to use target attribute

<a href="newsletter_01.pdf" target="_blank">

Upvotes: 2

gkalpak
gkalpak

Reputation: 48211

Change the <a> tag like this:

<a href="newsletter_01.pdf" target="_blank">

You can find more about the target attribute here.

Upvotes: 0

Related Questions