Base href Property
Example
Return the base URL for all relative URLs on a page:
var x = document.getElementById("myBase").href;
Try it Yourself »
Definition and Usage
The href property sets or returns the value of the href attribute in a base element.
The href attribute specifies a base URL for all relative URLs on a page.
By default, the base URL is the location of the current document, but it can be overridden by this property.
Browser Support
Property | |||||
---|---|---|---|---|---|
href | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the href property:
baseObject.href
Set the href property:
baseObject.href = URL
Property Values
Value | Description |
---|---|
URL | Specifies the base URL |
Technical Details
Return Value: | A String, representing the base URL for all relative URLS on a page, including the protocol (like http://) |
---|
More Examples
Example
Change the value of the base URL:
document.getElementById("myBase").href = "https://www.w3schools.com/html/";
Try it Yourself »
Related Pages
HTML reference: HTML <base> href attribute
❮ Base Object