The target
attribute from base
element
sets the default target for all hyperlinks and forms in that page.
The target
property sets or gets
the value of the target
attribute in a base
element.
target |
Yes | Yes | Yes | Yes | Yes |
Return the target property:
var aURL = baseObject.target;
Set the target property:
baseObject.target=_blank|_self|_parent|_top|framename;
Value | Description |
---|---|
_blank | Open link in a new window |
_self | Default. Open link in the same frame as it was clicked |
_parent | Open links in the parent frameset |
_top | Open links in the body of the window |
framename | Open links in a named frame |
A target value.
The following code shows how to get the base target.
<!DOCTYPE html>
<html>
<head>
<base id="myBase" target="_self" href="http://www.java2s.com/new/">
</head><!-- ww w . j a va 2 s .c om-->
<body>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
var x = document.getElementById("myBase").target;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set new base target value.
<!DOCTYPE html>
<html>
<head>
<base id="myBase" href="http://www.java2s.com/new/">
</head><!--from w w w .j a v a2 s .c o m-->
<body>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myBase").target = "_blank";
document.getElementById("demo").innerHTML = "set.";
}
</script>
</body>
</html>
The code above is rendered as follows: