如何使 HTML 在另一个窗口或选项卡中打开超链接?

这是 HTML 中超链接的一行:

<a href="http://www.starfall.com/">Starfall</a>

因此,如果我点击“ Starfall”,我的浏览器-我正在使用火狐-将带我到新的页面,我的窗口的内容将发生变化。我想知道,如何在 HTML 中做到这一点,以便新页面在一个新窗口中打开,而不是更改前一个窗口?HTML 中有这样的方法吗?

如果是,有没有办法在浏览器的另一个标签页(而不是另一个窗口)打开请求的页面?

229068 次浏览

use target="_blank"

<a target='_blank' href="http://www.starfall.com/">Starfall</a>

<a href="http://www.starfall.com/" target="_blank">Starfall</a>

Whether it opens in a tab or another window though is up to how a user has configured her browser.

You should be able to add

target="_blank"

like

<a href="http://www.starfall.com/" target="_blank">Starfall</a>

Simplest way is to add a target tag.

<a href="http://www.starfall.com/" target="Starfall">Starfall</a>

Use a different value for the target attribute for each link if you want them to open in different tabs, the same value for the target attribute if you want them to replace the other ones.

the target = _blank is will open in new tab or windows based on browser setting.

To force a new window use javascript onclick all three parts are needed. url, a name, and window width and height size or it will just open in a new tab.

<a onclick="window.open('http://www.starfall.com/','name','width=600,height=400')">Starfall</a>

The target attribute is your best way of doing this.

<a href="http://www.starfall.com" target="_blank">

will open it in a new tab or window. As for which, it depends on the users settings.

<a href="http://www.starfall.com" target="_self">

is default. It makes the page open in the same tab (or iframe, if that's what you're dealing with).
The next two are only good if you're dealing with an iframe.

<a href="http://www.starfall.com" target="_parent">

will open the link in the iframe that the iframe that had the link was in.

<a href="http://www.starfall.com" target="_top">

will open the link in the tab, no matter how many iframes it has to go through.

below example with target="_blank" works for Safari and Mozilla

<a href="http://www.starfall.com" `target="_blank"`>

Using target="new"worked for Chrome

<a href="http://www.starfall.com" `target="new"`>

You can also accomplish this by adding the following to your page's header:

<base target="_blank">

This will make ALL links on your page open in a new tab

Since web is evolving quickly, some things changes with time. For security issues, you might want to use the rel="noopener" attribute in conjuncture with your target="_blank".

Like stated in Google Dev Documentation, the other page can access your window object with the window.opener property. Your external link should looks like this now:

<a href="http://www.starfall.com/" target="_blank" rel="noopener">Starfall</a>