diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/html/element/base | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/html/element/base')
-rw-r--r-- | files/zh-cn/web/html/element/base/index.html | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/files/zh-cn/web/html/element/base/index.html b/files/zh-cn/web/html/element/base/index.html new file mode 100644 index 0000000000..138ff49ba0 --- /dev/null +++ b/files/zh-cn/web/html/element/base/index.html @@ -0,0 +1,128 @@ +--- +title: <base>:文档根 URL 元素 +slug: Web/HTML/Element/base +tags: + - HTML + - 元素 + - 文档 +translation_of: Web/HTML/Element/base +--- +<div>{{HTMLRef}}</div> + +<p><strong>HTML <base> 元素</strong> 指定用于一个文档中包含的所有相对 URL 的根 URL。一份中只能有一个 <base> 元素。</p> + +<p>一个文档的基本 URL, 可以通过使用 {{domxref('document.baseURI')}} 的 JS 脚本查询。如果文档不包含 <code><base></code> 元素,<code>baseURI</code> 默认为 <code>{{domxref("document.location.href")}}</code>。</p> + +<table class="properties"> + <tbody> + <tr> + <th><a href="/zh-CN/docs/Web/HTML/Content_categories">内容类别</a></th> + <td>元数据内容。</td> + </tr> + <tr> + <th>合法的内容</th> + <td>无,它是一个{{Glossary("empty element")}}</td> + </tr> + <tr> + <th><dfn>标签省略</dfn></th> + <td>该标签不能有结束标签。</td> + </tr> + <tr> + <th>合法的父级</th> + <td>任何不带有任何其他 {{HTMLElement("base")}} 元素的{{HTMLElement("head")}} 元素</td> + </tr> + <tr> + <th>合法的 ARIA 角色</th> + <td>无</td> + </tr> + <tr> + <th>DOM 接口</th> + <td>{{domxref("HTMLBaseElement")}}</td> + </tr> + </tbody> +</table> + +<h2 id="属性">属性</h2> + +<p>该标签包含<a href="/zh-CN/docs/HTML/Global_attributes">全局属性</a>。</p> + +<p>如果指定了以下任一属性,这个元素<strong>必须</strong>在其他任何属性是URL的元素之前。例如:<code>{{HTMLElement("link")}}</code> 的 <code>href</code> 属性。</p> + +<dl> + <dt>{{htmlattrdef("href")}}</dt> + <dd>用于文档中相对 URL 地址的基础 URL。允许绝对和相对URL。</dd> + <dt>{{htmlattrdef("target")}}</dt> + <dd>默认浏览上下文的关键字或作者定义的名称,当没有明确目标的链接 <code>{{HTMLElement("a")}}</code> 或表单 <code>{{HTMLElement("form")}}</code> 导致导航被激活时显示其结果。该属性值定位到<em>浏览上下文</em>(例如选项卡,窗口或内联框 <code>{{HTMLElement("iframe")}}</code> )。</dd> + <dd>以下的关键字指定特殊的意思: + <ul> + <li><code>_self</code>: 载入结果到当前浏览上下文中。(该值是元素的默认值)。</li> + <li><code>_blank</code>: 载入结果到一个新的未命名的浏览上下文。</li> + <li><code>_parent</code>: 载入结果到父级浏览上下文(如果当前页是内联框)。如果没有父级结构,该选项的行为和<code>_self</code>一样。</li> + <li><code>_top</code>: 载入结果到顶级浏览上下文(该浏览上下文是当前上下文的最顶级上下文)。如果没有父级,该选项的行为和_self一样。</li> + </ul> + </dd> +</dl> + +<h2 id="使用说明">使用说明</h2> + +<h3 id="多个_<base>_元素">多个 <code><base></code> 元素</h3> + +<p>如果指定了多个 <code><base></code> 元素,只会使用第一个 <code>href </code>和 <code>target </code>值, 其余都会被忽略。</p> + +<h3 id="页内锚">页内锚</h3> + +<p>指向文档中某个片段的链接,例如 <code><a href="#some-id"></code> 用 <code><base></code> 解析,触发对带有附加片段的基本 URL 的 HTTP 请求。</p> + +<p>例如:给定 <code><base href="https://example.com"></code></p> + +<p>以及此链接 <code><a href="#anchor">Anker</a></code></p> + +<p>链接指向 <code>https://example.com/#anchor</code></p> + +<h3 id="Open_Graph">Open Graph</h3> + +<p><a href="https://ogp.me">Open Graph</a> 标签不接受 <code><base></code>,并且应该始终具有完整的绝对URL。例如:</p> + +<pre><code><meta property="og:image" content="https://example.com/thumbnail.jpg"></code></pre> + +<h2 id="示例">示例</h2> + +<pre class="brush: html"><base href="http://www.example.com/"> +<base target="_blank"> +<base target="_top" href="http://www.example.com/"> +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">注释</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', 'semantics.html#the-base-element', '<base>')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>上次快照之后没有变化。</td> + </tr> + <tr> + <td>{{SpecName('HTML5 W3C', 'document-metadata#the-base-element', '<base>')}}</td> + <td>{{Spec2('HTML5 W3C')}}</td> + <td><font face="Arial, x-locale-body, sans-serif"><span style="background-color: rgba(212, 221, 228, 0.14902);">指定 </span></font><code>target</code> 的行为</td> + </tr> + <tr> + <td>{{SpecName('HTML4.01', 'struct/links.html#h-12.4', '<base>')}}</td> + <td>{{Spec2('HTML4.01')}}</td> + <td>添加 <code>target</code> 属性</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div class="hidden">此页面中的兼容性表是根据结构化数据生成的。 如果您想贡献数据,请查看 <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 并向我们发送拉取请求。</div> + +<p>{{Compat("html.elements.base")}}</p> |