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
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 document
.baseURI<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
to obtain the base URL of an element.element
.baseURI
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Node: baseURI' in that specification. | Living Standard |
Browser compatibility
BCD tables only load in the browser
See also
<base>
element (HTML)xml:base
attribute (XML documents).Node.baseURIObject
- a variant of this API for Mozilla add-ons and internal code. Returns the base URL as annsIURI
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论