The Base object represents an HTML <base> element.
We can access a <base> element by using document.getElementById()
:
Click the button to get the URL of the base element.
<!DOCTYPE html> <html> <head> <base id="myBase" href="https://www.java2s.com/"> </head>/*from ww w . j a v a 2 s .c o m*/ <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myBase").href; document.getElementById("demo").innerHTML = x; } </script> </body> </html>