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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章