HTML DOM
The href property of the HTMLBaseElement interface contains a string that is the URL to use as the base for relative URLs.
It reflects the href attribute of the base element.
Value
A string that contains a URL, or the empty string ("") if the corresponding <base> element does not include the href attribute.
Examples
HTML with base URL
This example demonstrates that the href attribute in <base> is reflected in the href property of HTMLBaseElement.
<pre id="log"></pre>
const logElement = document.querySelector("#log");
function log(text) {
logElement.innerText = text;
}
#log {
height: 20px;
}
HTML
<base href="https://developer.mozilla.org/example" />
JavaScript
const base = document.getElementsByTagName("base")[0];
log(`base.href="${base.href}"`);
Result
HTML with base URL
Specifications
Browser compatibility
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
