HTML
<base>
element
specifies the base URL to use for all
relative
URLs in a document.
There can be only one
<base>
元素在文档中。
A document's used base URL can be accessed by scripts with
document.baseURI
. If the document has no
<base>
elements, then
baseURI
默认为
location.href
.
| 内容类别 | Metadata content. |
|---|---|
| 准许内容 | None, it is an empty element . |
| Tag omission | There must be no closing tag. |
| Permitted parents |
A
<head>
that doesn't contain another
<base>
元素。
|
| Implicit ARIA role | 无对应角色 |
| Permitted ARIA roles |
No
role
permitted
|
| DOM 接口 |
HTMLBaseElement
|
This element's attributes include the 全局属性 .
If either of the following attributes are specified, this element
must
come before other elements with attribute values of URLs, such as
<link>
’s
href
属性。
href
The base URL to be used throughout the document for relative URLs. Absolute and relative URLs are allowed.
target
<a>
,
<area>
,或
<form>
elements without explicit
target
属性。
_self
(default): Show the result in the current browsing context.
_blank
: Show the result in a new, unnamed browsing context.
_parent
: Show the result in the parent browsing context of the current one, if the current page is inside a frame. If there is no parent, acts the same as
_self
.
_top
: Show the result in the topmost browsing context (the browsing context that is an ancestor of the current one and has no parent). If there is no parent, acts the same as
_self
.
若多个
<base>
elements are used, only the first
href
and first
target
are obeyed — all others are ignored.
Links pointing to a fragment in the document — e.g.
<a href="#some-id">
— are resolved with the
<base>
, triggering an HTTP request to the base URL with the fragment attached. For example:
<base href="https://example.com">
<a href="#anchor">Anker</a>
https://example.com/#anchor
.
Open Graph
tags do not acknowledge
<base>
, and should always have full absolute URLs. For example:
<meta property="og:image" content="https://example.com/thumbnail.jpg">
<base href="https://www.example.com/"> <base target="_blank"> <base target="_top" href="https://example.com/">
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of '<base>' in that specification. |
实时标准 | No change since last snapshot. |
|
HTML5
The definition of '<base>' in that specification. |
推荐 |
Specified the behavior of
target
|
|
HTML 4.01 Specification
The definition of '<base>' in that specification. |
推荐 |
添加
target
属性
|
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
base
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 1 |
IE
完整支持
Yes
注意事项
|
Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
href
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
target
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持
见实现注意事项。