Base href Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Base

Description

The href property sets or gets the href attribute in a base element, which controls a base URL for all relative URLs on a page.

Set the href property with the following Values

Value Description
URL Sets the base URL

Return Value

A String, representing the base URL for all relative URLS on a page

The following code shows how to return the base URL for all relative URLs on a page:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<base id="myBase" href="/jsref/">
</head>/*from   w w  w  .j  a v a  2 s  .  co  m*/
<body>

<a href="default.asp">Default</a>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
    var v = document.getElementById("myBase").href;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials