<base>: The Document Base URL element
<base> HTML 元素指定用于文档中所有相对 URL 的基本 URL。文档中只能有一个 <base> 元素。
¥The <base> HTML element specifies the base URL to use for all relative URLs in a document. There can be only one <base> element in a document.
文档使用的基本 URL 可以通过带有 Node.baseURI 的脚本访问。如果文档没有 <base> 元素,则 baseURI 默认为 location.href。
¥A document's used base URL can be accessed by scripts with Node.baseURI. If the document has no <base> elements, then baseURI defaults to location.href.
属性
¥Attributes
该元素的属性包括 全局属性。
¥This element's attributes include the global attributes.
警告:
<base>元素必须具有href属性、target属性或两者。如果至少指定了这些属性之一,则<base>元素必须位于属性值为 URL 的其他元素之前,例如<link>的href属性。¥Warning: A
<base>element must have anhrefattribute, atargetattribute, or both. If at least one of these attributes are specified, the<base>element must come before other elements with attribute values that are URLs, such as a<link>'shrefattribute.
href-
整个文档中用于相对 URL 的基本 URL。允许使用绝对和相对 URL。不允许使用
data:和javascript:URL。 target-
默认 browsing context 的关键字或作者定义的名称,用于显示从
<a>、<area>或<form>元素导航的结果,而无需显式target属性。以下关键字具有特殊含义:_self(默认):在当前浏览上下文中显示结果。_blank:在新的、未命名的浏览上下文中显示结果。_parent:如果当前页面位于框架内,则在当前页面的父浏览上下文中显示结果。如果没有父级,则与_self相同。_top:在最顶层的浏览上下文(当前浏览上下文的祖级并且没有父浏览上下文)中显示结果。如果没有父级,则与_self相同。
使用说明
多个 <base> 元素
页内锚点
¥In-page anchors
指向文档中片段的链接 - 例如 <a href="#some-id"> — 使用 <base> 进行解析,触发对附加片段的基本 URL 的 HTTP 请求。
¥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.
例如,给定 <base href="https://example.com/"> 和此链接:<a href="#anchor">To anchor</a>。该链接指向 https://example.com/#anchor。
¥For example, given <base href="https://example.com/"> and this link: <a href="#anchor">To anchor</a>. The link points to https://example.com/#anchor.
目标可能不包含 ASCII 换行符、制表符或 <
¥target may not contain ASCII newline, tab, or <
如果 target 属性包含 ASCII 换行符、制表符或 < 字符,则该值将重置为 _blank。这是为了防止悬垂标记注入攻击,这是一种无脚本攻击,其中未关闭的 target 属性被注入到页面中,以便捕获任何后续文本,直到浏览器到达关闭该属性的字符。
¥If the target attribute contains an ASCII newline, tab, or the < character, the value is reset to _blank.
This is to prevent dangling markup injection attacks, a script-less attack in which an unclosed target attribute is injected into the page so that any text that follows is captured until the browser reaches a character that closes the attribute.
打开图
¥Open Graph
打开图 标签不承认 <base>,并且应始终具有完整的绝对 URL。例如:
¥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" />
示例
技术总结
¥Technical summary
| 内容类别 | 元数据内容。 |
|---|---|
| 允许的内容 | 没有任何;这是 void element。 |
| 标签遗漏 | 必须有开始标记,并且不能有结束标记。 |
| 允许的父级 | 不包含另一个 <base> 元素的 <head>。 |
| 隐式 ARIA 角色 | 没有对应的角色 |
| 允许的 ARIA 角色 | 不允许 role |
| DOM 接口 | HTMLBaseElement |
规范
| Specification |
|---|
| HTML Standard # the-base-element |
浏览器兼容性
BCD tables only load in the browser
¥Browser compatibility