Base target Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Base

Description

The target property sets or gets the target attribute in a base element, which controls the default target for all hyperlinks and forms in the page.

Set the target property with the following Values

Value Description
_blankOpen links in a new window
_self Open links in the same frame as it was clicked (this is default)
_parent Open links in the parent frameset
_top Open links in the full body of the window
framename Open links in a named frame

Return Value

A String, representing the default target for all hyperlinks and forms in the page

The following code shows how to return the base target for all links on a page:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<base id="myBase" href="https://www.java2s.com/jsref/">
</head>/*  ww w.  j ava 2s.c om*/
<body>

<p><a href="https://www.java2s.com/">java2s.com</a></p>
<p><a href="https://www.java2s.com/">java2s.com</a></p>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var v = document.getElementById("myBase").target;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials