baseURI 只读特性返回绝对基 URL 为 节点 .

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> 元素的 src attribute or XML xlink :href 属性。

In most cases the base URL is simply 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.

句法

var nodeBaseURI = node.baseURI;
					

A DOMString representing the base URL of the specified 节点 . 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).

细节

文档的基 URL

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)

HTML 实时标准的基 URL 章节 了解细节。

可以使用 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.

元素的基 URL

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 了解细节。

可以使用 element .baseURI 以获得元素的基 URL。

规范

规范 状态 注释
DOM
在该规范中的 Node: baseURI 定义。
实时标准

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
baseURI Chrome Yes Edge 12 Firefox 1 IE ? Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: