Change the base target for all links on a page to "_blank":
document.getElementById("myBase").target = "_blank";
Click the button to set the value of the target attribute of ALL links on a page to "_blank".
<!DOCTYPE html> <html> <head> <base id="myBase" href="https://www.java2s.com/"> </head>//from w ww . j a v a 2 s. c om <body> <p><a href="https://www.java2s.com/">Examples</a></p> <p><a href="index.html">Examples</a></p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myBase").target = "_blank"; document.getElementById("demo").innerHTML = "the target attribute changed."; } </script> </body> </html>