Base target Property - Change the base target for all links on a page to "_blank": - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Base

Description

Base target Property - Change the base target for all links on a page to "_blank":

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 av a 2  s  . c o m*/
<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()">set the value of the target attribute of ALL links on a page to "_blank"</button>

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

<script>
function myFunction() {
    document.getElementById("myBase").target = "_blank";
    document.getElementById("demo").innerHTML = "The value of the target attribute was set.";
}
</script>

</body>
</html>

Related Tutorials