Return the base target for all links on a page:
var x = document.getElementById("myBase").target;
Click the button to return the value of the target attribute of the base element.
<!DOCTYPE html> <html> <head> <base id="myBase" target="_self" href="https://www.java2s.com/jsref/"> </head>//from w w w . ja va 2 s.co m <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myBase").target; document.getElementById("demo").innerHTML = "Base target for all links: " + x; } </script> </body> </html>
The target
property sets or gets the target attribute in a base element.
The target attribute specifies the default target for all hyperlinks and forms in the page.
Property Values
Value | Description |
---|---|
_blank | Open in a new window |
_self | Open in the same frame. Default |
_parent | Open in the parent frameset |
_top | Open in the full body of the window |
framename | Open in a named frame |
The target
property returns the default target for all hyperlinks and forms in the page.