Home  >  Article  >  Web Front-end  >  HTML tag specifies the default address or default target for all links on the page

HTML tag specifies the default address or default target for all links on the page

WBOY
WBOYOriginal
2016-09-14 09:24:021859browse

Definition and Usage

The

tag specifies the default address or default target for all links on the page.

Normally, the browser will fill in the gaps in the relative URL by extracting the corresponding elements from the URL of the current document.

Use the tag to change this. The browser will then no longer use the URL of the current document, but will use the specified base URL to resolve all relative URLs. This includes URLs in , , ,

tags.

tag must be located inside the head element.

Optional attributes

Property Value Description
target
  • _blank
  • _parent
  • _self
  • _top
  • framename
Where to open all the links on the page.

Case:

<html>
<head>
<<span style="color: #0000ff;">base</span> href=<span style="color: #800000;">"</span><span style="color: #800000;">http://www.w3school.com.cn/i/</span><span style="color: #800000;">"</span> />
<<span style="color: #0000ff;">base</span> target=<span style="color: #800000;">"</span><span style="color: #800000;">_blank</span><span style="color: #800000;">"</span> />
</head>

<body>
<img src=<span style="color: #800000;">"</span><span style="color: #800000;">eg_smile.gif</span><span style="color: #800000;">"</span> /><br />
<p>请注意,我们已经为图像规定了一个相对地址。由于我们已经在 head 部分规定了一个基准 URL,浏览器将在如下地址寻找图片:</p>
<p><span style="color: #800000;">"</span><span style="color: #800000;">http://www.w3school.com.cn/i/eg_smile.gif</span><span style="color: #800000;">"</span></p>

<br /><br />
<p><a href=<span style="color: #800000;">"</span><span style="color: #800000;">http://www.w3school.com.cn</span><span style="color: #800000;">"</span>>W3School</a></p>
<p>请注意,链接会在新窗口中打开,即使链接中没有 target=<span style="color: #800000;">"</span><span style="color: #800000;">_blank</span><span style="color: #800000;">"</span> 属性。这是因为 <span style="color: #0000ff;">base</span> 元素的 target 属性已经被设置为 <span style="color: #800000;">"</span><span style="color: #800000;">_blank</span><span style="color: #800000;">"</span> 了。</p>

</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=<span style="color: #800000;">"</span><span style="color: #800000;">Content-Type</span><span style="color: #800000;">"</span> content=<span style="color: #800000;">"</span><span style="color: #800000;">text/html; charset=gb2312</span><span style="color: #800000;">"</span> />
<meta http-equiv=<span style="color: #800000;">"</span><span style="color: #800000;">Content-Language</span><span style="color: #800000;">"</span> content=<span style="color: #800000;">"</span><span style="color: #800000;">zh-cn</span><span style="color: #800000;">"</span> />

<<span style="color: #0000ff;">base</span> target=<span style="color: #800000;">"</span><span style="color: #800000;">_blank</span><span style="color: #800000;">"</span> />
</head>

<body>

<p>
<a href=<span style="color: #800000;">"</span><span style="color: #800000;">http://www.w3school.com.cn</span><span style="color: #800000;">"</span> target=<span style="color: #800000;">"</span><span style="color: #800000;">_blank</span><span style="color: #800000;">"</span>>这个连接</a> 将在新窗口中加载,因为 target 属性被设置为 <span style="color: #800000;">"</span><span style="color: #800000;">_blank</span><span style="color: #800000;">"</span><span style="color: #000000;">。
</span></p>

<p>
<a href=<span style="color: #800000;">"</span><span style="color: #800000;">http://www.w3school.com.cn</span><span style="color: #800000;">"</span>>这个连接</a><span style="color: #000000;"> 也将在新窗口中加载,即使没有 target 属性。
</span></p>

</body>
</html>

Base object

The Base object represents the base element of HTML.

Every time appears in an HTML document, a Base object is created.

Base object properties

Property Description
href Set or return the base URL for all links in the page.
id Sets or returns the id of the element.
target Set or return the default target frame for all links in the page.