Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open link in new tab or window [duplicate]

Is it possible to open an a href link in a new tab instead of the same tab?

<a href="http://your_url_here.html">Link</a> 
like image 707
Rene Avatar asked Mar 21 '13 15:03

Rene


People also ask

Is it better to open link in new tab?

The only time it is recommended that you open a link in a new tab is when opening in the same screen would interrupt a process (e.g. when a user is filling out a form or viewing a video). Linking in the same tab or screen in these situations could cause the user to lose the work they've done or have to start over.

How do I make a link open in a new tab instead of a new window?

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.

How do I force a link to open in the same tab?

Use _self in target attribute of anchor tag to Open link in same tab in HTML webpage.

What is the difference between opening a new tab and opening a new window?

A tab is more or less same as a window. A window can contain several tabs and all session data and cookies are shared across all tabs and open window. It's better to open a lot of tabs than opening several windows because too many window becomes too cluttered to handle.


2 Answers

You should add the target="_blank" and rel="noopener noreferrer" in the anchor tag.

For example:

<a target="_blank" rel="noopener noreferrer" href="http://your_url_here.html">Link</a> 

Adding rel="noopener noreferrer" is not mandatory, but it's a recommended security measure. More information can be found in the links below.

Source:

  • MDN | HTML element <a> | attribute target
  • About rel=noopener
  • Opens External Anchors Using rel="noopener"
like image 192
Nathan Avatar answered Oct 02 '22 12:10

Nathan


It shouldn't be your call to decide whether the link should open in a new tab or a new window, since ultimately this choice should be done by the settings of the user's browser. Some people like tabs; some like new windows.

Using _blank will tell the browser to use a new tab/window, depending on the user's browser configuration and how they click on the link (e.g. middle click, Ctrl+click, or normal click).

like image 33
gotson Avatar answered Oct 02 '22 13:10

gotson