Node.baseURI - Web APIs 编辑

The baseURI read-only property returns the absolute base URL of a Node.

The base URL is used to resolve relative URLs when the browser needs to obtain an absolute URL, for example when processing the HTML <img> element's src attribute or XML xlink:href attribute.

In most cases the base URL is the location of the document, but it can be affected by many factors, including the <base> element in HTML and the xml:base attribute in XML.

Syntax

var nodeBaseURI = node.baseURI;

Value

A DOMString representing the base URL of the specified Node. It may be null if unable to obtain an absolute URI. Although this property is read-only, its value may change in certain situations (see below).

Details

The base URL of a document

The base URL of a document defaults to the document's address (as displayed by the browser and available in window.location), but it can be changed:

  • When an HTML <base> tag is found in the document
  • When the document is new (created dynamically)

See the Base URLs section of the HTML Living standard for details.

You can use document.baseURI to obtain the base URL of a document. Note that obtaining the base URL for a document may return different URLs over time if the <base> tags or the document's location change.

The base URL of an element

The base URL of an element in HTML normally equals the base URL of the document the node is in.

If the document contains xml:base attributes (which you shouldn't do in HTML documents), the element.baseURI takes the xml:base attributes of element's parents into account when computing the base URL. See xml:base for details.

You can use element.baseURI to obtain the base URL of an element.

Specifications

SpecificationStatusComment
DOM
The definition of 'Node: baseURI' in that specification.
Living Standard

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:138 次

字数:4827

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文