Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make all <a> tags open in a new window/tab?

Tags:

html

hyperlink

I'm making a webpage with a lot of links, which should all open in a new tab using target="_blank".

Is it possible to apply this to all <a> tags by default, so I can spare the time by not inserting it a every link?

like image 849
StevoHN Avatar asked Oct 07 '15 07:10

StevoHN


People also ask

How do I make tags 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 can you force the browser to open a link in a new window or tab?

To open a link in a new browser window, hold the Shift on then click the link or right-click the link and select Open link in New Window.

How do I get a new tab to open automatically in HTML?

Well, there is a native HTML tag to handle such cases automatically. You don't need to manually add target="_blank" in all the tag. Just add target="_blank" in the base tag, it will open in a new tab for all the link present in the webpage.


1 Answers

Yes - you can specify a base target in the page's head:

<head>
    <base target="_blank">
</head>

Source.

If you need to override this for a particular link so that it doesn't open in a new window, you can do this manually by setting that link's target to "_self".

like image 186
Sinister Beard Avatar answered Nov 15 '22 06:11

Sinister Beard