How to open link in new tab on html?

I'm working on an HTML project, and I can't find out how to open a link in a new tab without javascript.

I already know that <a href="http://www.WEBSITE_NAME.com"></a> opens the link in same tab. Any ideas how to make it open in a new one?


Set the 'target' attribute of the link to _blank :

<a href="#" target="_blank">Link</a>

Edit: for other examples, see here: http://www.w3schools.com/tags/att_a_target.asp

(Note: I previously suggested blank instead of _blank because, if used, it'll open a new tab and then use the same tab if the link is clicked again. However, this is only because, as GolezTrol pointed out, it refers to the name a of a frame/window, which would be set and used when the link is pressed again to open it in the same tab).


Use one of these as per your requirements.

Open the linked document in a new window or tab:

 <a href="xyz.html" target="_blank"> Link </a>

Open the linked document in the same frame as it was clicked (this is default):

 <a href="xyz.html" target="_self"> Link </a>

Open the linked document in the parent frame:

 <a href="xyz.html" target="_parent"> Link </a>

Open the linked document in the full body of the window:

 <a href="xyz.html" target="_top"> Link </a>

Open the linked document in a named frame:

 <a href="xyz.html" target="framename"> Link </a>

See MDN


If you would like to make the command once for your entire site, instead of having to do it after every link. Try this place within the Head of your web site and bingo.

<head>
<title>your text</title>
<base target="_blank">
</head>

hope this helps

链接地址: http://www.djcxy.com/p/6234.html

上一篇: 为什么我不能在Java中使用SimpleDateFormat一年?

下一篇: 如何在html上的新标签中打开链接?