Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to force a link to be opened in a new tab using javascript

i want to make sure that in all tab enabled browsers, when a user clicks a link, it opens in a new tab. All i have got so far is the target keyword in the anchor, but is there some new html attribute that supports that function?

like image 476
Nauman Bashir Avatar asked Nov 22 '10 09:11

Nauman Bashir


People also ask

How do I force a link to open in a new tab?

You can make a HTML link open in a new tab by adding the target=”_blank” attribute. You should insert this after the link address.

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

Use Mouse or Trackpad Only If you use a mouse, simply utilizing the middle mouse button to click on a link will immediately open it in a new browser tab! Holding down the Shift key while middle-clicking also helps you switch to the tab automatically. Trackpads on Windows laptops can also open links in new tabs.


3 Answers

There is no guaranteed way for that because you can change window opening behavior and tabbing options from within browser options.

The best you can do is to write your code using either target="_blank" or window.open().

like image 92
Sarfraz Avatar answered Oct 05 '22 18:10

Sarfraz


There is a CSS3-property target-new

Unfortunately it isn't supported yet by any browser(I don't know any). But maybe you could already implement it for future use.

like image 27
Dr.Molle Avatar answered Oct 05 '22 18:10

Dr.Molle


Your best bet is <a href="..." target="_blank"></a>.

There is no standardized semantic way of telling the browser to open a new tab. This is because not all browsers have tabs. Take most mobile browsers, for example, they don't have tabs.

There is also no vendor specific way of doing this that I know of.

like image 41
August Lilleaas Avatar answered Oct 05 '22 18:10

August Lilleaas