Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open link in a new tab in 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 the same tab. Any ideas how to make it open in a new one?

like image 785
ZenthyxProgramming Avatar asked Jul 17 '13 22:07

ZenthyxProgramming


People also ask

How do I make a link open in a new tab?

Method 1: Ctrl+Click The first method requires a keyboard and a mouse or trackpad. Simply press and hold the Ctrl key (Cmd on a Mac) and then click the link in your browser. The link will open in a new tab in the background.

Which tag opens link in new tab?

The _blank value in the target attribute of the anchor tag opens the link in the new tab. The anchor tag <a> defines a hyperlink used to link from one page to another. The href attribute sets the URL of the page you want to link to. The option target="_blank" switches the link to the new tab.

How do I link to another page in HTML?

To make page links in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the link starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a link. Add the URL for the link in the <a href=” ”>.


Video Answer


2 Answers

Set the target attribute of the link to _blank:

<a href="#" target="_blank" rel="noopener noreferrer">Link</a> 

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.


Security Consideration!

The rel="noopener noreferrer" is to prevent the newly opened tab from being able to modify the original tab maliciously. For more information about this vulnerability read the following articles:

  • The target="_blank" vulnerability by example
  • External Links using target='_blank'
like image 198
SharkofMirkwood Avatar answered Oct 14 '22 03:10

SharkofMirkwood


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

like image 30
Learner Always Avatar answered Oct 14 '22 05:10

Learner Always