HTML 标签

href="/jimtao/css/item/08d75134163d094e241f1464.css" type="text/css" rel="stylesheet" /> href="/space.css" type="text/css" rel="stylesheet" />
HTML <base>标签
2007年06月19日 星期二 下午 11:33

本页打开 百度首页

代码:
<a href="http://www.baidu.com/" >百度首页</a>

新页打开 百度首页

代码:
<a href="http://www.baidu.com/" target="_blank">百度首页</a>

---base标签---

  使用<base>标签最主要的原因,是为了确保文档中所有的相对URL都可以被分解成正确的文档地址,即使在文档本身被移动或重命名的情况下也可以正确解析。

  在创建文档集合时,使用<base>标签尤为重要。通过在每个文档中放置正确的<base>标签,就可以在目录甚至服务器之间移动整个文档集合,而不会破坏文档中任何链接。如果想要让用户查询指向一个与主文档URL不同的URL,那么也需要为可搜索文档(< isindex>)使用<base>标签。

  当文档同事包含<isindex>标签和其他相对URL时,如果相对URL与所希望的索引处理URL无关,那么就可能会出现问题。正因为这个原因,所以请不要在使用<base>标签的可搜索文档中用相对URL来指定文档的查询URL。

  例如:

  <base href="http://www.w3schools.com/images/
";> 那么,整个页面的相对地址就是在http://www.w3schools.com/images/底下展开的。不管移动到何处。

代码:
<head>
<base href="http://www.w3schools.com/images/" />
</head>
<img src="smile.gif" />

相当于:

代码:
<head>
</head>
<img src="http://www.w3schools.com/images/smile.gif" />

HTML <base>标签
w3pop.com / 2006-09-26

Definition and Usage
用法

The base element specifies a base URL for all the links in a page.
使用base元素为页面所有的连接指定一个基础的URL

Differences Between HTML and XHTML
在HTML和XHTML中的区别

In HTML the <base> tag has no end tag.
在HTML中<base>标签不需要结束标签

In XHTML the <base> tag must be properly closed.
在XHTML中<base>标签必须合理关闭

Tips and Notes
注意点

Note: The <base> tag must go inside the head element.
注意:<base>标签必须使用在head元素内

Example
实例

Assume that the absolute address for an image is:
假设有一个图片的绝对地址:

<img src="http://www.w3schools.com/images/smile.gif" />

Now we insert the <base> tag, which specifies a base URL for all of the links in a page, in the head section of a page:
现在我们插入<base>标签,就可以为页面内的所有连接加上基础URL:

<head>
<base href="http://www.w3schools.com/images/" />
</head>

When inserting images on the page in the example above, we just have to specify the relative address, and the browser will look for that file using the full URL, "http://www.w3schools.com/images/smile.gif":
加上之后我们只需要指定相对的地址就可以将URL变为"http://www.w3schools.com/images/smile.gif":

<img src="smile.gif" />

Required Attributes
必要属性

DTD indicates in which DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.
下表中的DTD列指明了被支持的DTD属性。S=Strict(精确的),T=Transitional(传统的),F=Frameset(框架)

属性 描述 DTD
href URL Specifies the URL to use as the base URL for links in the page
为页面的所有连接指定基础URL
STF

Optional Attributes
可选属性

属性 描述 DTD
target _blank
_parent
_self
_top
Where to open all the links on the page. This attribute can be overridden by using the target attribute in each link.
页面中所有连接的打开方式。如果每个连接使用了target属性那么base的target属性就无效了
  • _blank - all the links will open in new windows
    所有的连接将在新窗口打开
  • _self - all the links will open in the same frame they where clicked
    所有的连接将在自身窗口或是框架中打开
  • _parent - all the links will open in the parent frameset
    所有连接在父级框架集中打开
  • _top - all the links will open in the full body of the window
    所有连接在窗口的主体中打开
TF

Standard Attributes and Events
标准属性以及事件

NONE

Try-It-Yourself Demos
演示

One target for all links
How to use the <base> tag to let all the links on a page have the same target.
怎样使用<base>标签来让所有连接使用同一个target


     
发布了20 篇原创文章 · 获赞 1 · 访问量 8万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章