Html 打开一个新标签来阅读 PDF 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16925481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:04:28  来源:igfitidea点击:

Opening a new tab to read a PDF file

htmlcss

提问by MultiWizard

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.

我可能在这里遗漏了一些简单的东西,但无论如何我都会问。我已经创建了一个打开 PDF 文件的链接,但是它在当前选项卡中打开而不是一个新选项卡。我应该在 HTML 中使用什么代码来打开一个新选项卡来阅读 PDF 文件。

<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>

回答by Chris

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

Target _blank will force the browser to open it in a new window

Target _blank 将强制浏览器在新窗口中打开它

回答by Chuck Le Butt

As everyone else has pointed out, this canwork:

正如其他人所指出的,这可以工作:

<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:

无法强制用户的浏览器在新选项卡中打开 PDF 文件。根据用户的浏览器设置,即使使用target="_blank"浏览器也可能有以下几种反应:

  1. Ask for action
  2. Open it in Adobe Acrobat
  3. Simply download the file directly to their computer
  1. 要求采取行动
  2. 在 Adob​​e Acrobat 中打开它
  3. 只需将文件直接下载到他们的计算机

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

看看 Firefox 的设置,例如:

enter image description here

在此处输入图片说明

Chrome has a similar setting:

Chrome 也有类似的设置:

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.

如果用户在遇到 PDF 时在浏览器设置中选择了“保存文件”,则您无法覆盖它。

回答by gkalpak

Change the <a>tag like this:

<a>像这样更改标签:

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

You can find more about the targetattribute here.

您可以在此处找到有关该target属性的更多信息。

回答by Nikola Mitev

You have to use target attribute

你必须使用目标属性

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

回答by Diogo Moreira

Just use targeton your tag <a>

只需target在您的标签上使用<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.

target 属性指定打开链接的位置。使用“_blank”将使您的浏览器打开一个新窗口/选项卡。

You could also use target in many ways. See http://www.w3schools.com/tags/att_a_target.asp

您还可以通过多种方式使用目标。见http://www.w3schools.com/tags/att_a_target.asp

回答by JustAnotherJohnDoe

Will open your pdf in a new tab with pdf viewer and can download too

将在带有 pdf 查看器的新选项卡中打开您的 pdf 并且也可以下载

<a className=""
   href="/project_path_to_your_pdf_asset/failename.pdf"
   target="_blank"
>
   View PDF
</a>

回答by Fastersixth

On Chrome this has proven to work well for me.

在 Chrome 上,这已被证明对我很有效。

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

回答by Waqas Khan

Use the below attribute in tag to open it in next tab

使用标签中的以下属性在下一个选项卡中打开它

target="_blank"

回答by Nishanth K Kumar

Try this, it worked for me.

试试这个,它对我有用。

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

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