HTML <base> Tag with the 'target' Attribute
<!DOCTYPE html>
<html>
<head>
<base href="http://www.html.am/" target="_blank">
</head>
<body>
<p><a href="tags/">HTML Tags</a></p>
</body>
</html>
Normally the above link would go to "tags/" of the current website (i.e. http://www.htmlcodes.ws/tags/). But now that we've used the "base" element to specify a base URL of "http://www.html.am", the link will actually resolve to http://www.html.am/tags/.
The target
Attribute
The target
attribute allows you to specify which browsing context to open the links in (eg, a new window, self, top, etc).
Possible values:
- _blank
- _self
- _top
- _parent
- Any string with at least one character that does not start with a
U+005F LOW LINE
character.
How to Use the above Code
- Replace the value of the
href
attribute to be the base URL that will be used for all relative links. - Replace the the rest of the code with your own code.
- Replace the value of the
target
attribute (or remove the attribute altogether). - Replace the rest of the content with you own.
About the <base>
Element
The <base>
element allows you to set a "base" URL for all relative links. Therefore, relative links will use the URL specified in the href
attribute of the <base>
tag.
The <base>
element doesn't affect absolute URLs (i.e. those that include the full path).