base

base 要素 (HTML)

[14] HTMLbase 要素型の要素は、 文書基底URI や基底対象枠を指定するために使用することができます。

[17] HTML での基底 URI に関しては、 HTML//基底URI も参照してください。

[15]

開始タグ
必須
終了タグ (HTML 2, HTML 4, ISO-HTML)
禁止
終了タグ (XHTML 1)
必須
内容模型
強制空要素
出現できる文脈
head 内の、参照を持つ要素の前に高々1個

仕様書

属性

href絶対URI(選択必須)基底 URI[HTML 2], [HTML 4]
id(なし)固有識別子[XHTML 1.0 SE], Microsoft Word
target%FrameTarget(選択必須)既定の対象枠[HTML 4] 非推奨

href 属性と target 属性のいずれかは必須です (が、 DTD でこれを表すことができないので、 両方の属性が存在する DTD では、両方省略可能になっています)。

出現できる文脈

[16] この要素は head 要素内に高々1個存在できますが HTML 4、 外部参照を持つ要素の前になければなりません HTML 4 仕様書

base 要素の前に来得る、 外部参照を持ち得る要素型は script, object, link です。 (スクリプト内やスタイルシート内の参照も含まれるのでしょうか? だとしたら style 要素や、 style 属性または事象系属性を持つ任意の要素が該当します。)

ところで、 head 要素自体も profile という値に URI を含む属性があります。でもそれ以前にもっていくのは不可能です。

[18] HTML 4 loose DTD でも base が出現可能なのは高々1回です。つまり、 href 用と target 用を別にするようなことはできない、 ということです。

状態

[5] base 要素は、HTML要素の状態に加え、 次の状態を持ちます。

凍結基底URL
文書基底URLの決定に使われる値です。 文書中にあるとき、値を持ちます >>128

凍結基底 URL

[127] Document木順で最初の href 属性つき base 要素は、凍結基底URL (frozen base URL) を持ちます >>128凍結基底URL文書基底URLの決定に用いられます。

[129] 次のような状況で同期的凍結基底URLの設定が行われなければなりません >>128

[132] 要素要素凍結基底URLの設定 (set the frozen base URL) は、 次のようにします >>128

  1. [6] 文書を、要素節点文書に設定します。
  2. [22] 結果を、要素href 内容属性の値に、 文書フォールバック基底URL文書文字符号化について、 URL構文解析器を適用した結果に設定します。
  3. [9] 結果が失敗なら、
    1. [10] 要素凍結基底URLを、文書フォールバック基底URLに設定します。
  4. [11] それ以外で、結果URLレコード文書CSP Is base allowed for Document? を適用した結果が「Blocked」 なら、
    1. [12] 要素凍結基底URLを、文書フォールバック基底URLに設定します。
  5. [13] それ以外なら、
    1. [20] 要素凍結基底URLを、結果URLレコードに設定します。

[136] これらの規定により、 base 要素によって設定される基底URLは、 それが文書基底URLとして用いられることになった時点で解決した値に固定されることになります。 フォールバック基底URLpushState などによって変化することがありますが、 それによって凍結基底URLは変化しません。

[137] なお、 base 要素href IDL属性はその時点で href 内容属性フォールバック基底URLに対して解決した値を返すので、 必ずしも凍結基底URLとは一致しません。

関連

[27] HTML には codebase 属性があって、特定の要素の特定の処理における基底 URI を別途指定できます。

XHTML を他のマーク語彙と組合せる時の base 要素の影響は規定されていませんから、 どう解釈されるかわかりませんので危険です。

base 要素の適用範囲

[8] 不思議マーク付け的には、 base 要素は次の base 要素が現れるまで有効なのだそうです (少なくても WinIE はこの通り動くらしい)。 basefont 要素と同じですね。

[33] WinIE (MSHTML) において、 base 要素が head 中に存在する場合、

(WinIE 6 on Windows XP SP2 で確認)

参考: agenda 2002-03(下旬) - Personnel http://members.jcom.home.ne.jp/jintrick/Personal/d20023l.html#d18_19

[34] >>33

>>3 のように body 内に複数 base を入れてみると、それ以降がすべて base に飲み込まれます。 base の終了タグがあっても無視されます。

(名無しさん 2005-05-29 07:33:55 +00:00)

[35] >>34 のテスト: http://suika.fam.cx/gate/cvs/*checkout*/www/test/html/base/base-in-body.html (名無しさん [sage])

[37] こういう変な包含関係は contentEditable でも生じるらしい

contentEditable - Anne’s Weblog about Markup & Style http://annevankesteren.nl/2005/07/contenteditable

(名無しさん [sage])

[38] >>33-35 WinIE 7 で修正される予定だそうです。

IEBlog : All your <base> are belong to us http://blogs.msdn.com/ie/archive/2005/08/29/457667.aspx

(名無しさん 2005-09-02 03:35:49 +00:00)

[64] 「base要素でいろいろ」@水無月ばけらのえび日記 http://bakera.jp/hatomaru.aspx/ebi/topic/2697 (名無しさん 2006-11-05 23:44:46 +00:00)

[65] crisp’s blog &#187; Blog Archive &#187; Broken parsers; the importance of BASE (2007-01-12 23:43:01 +09:00 版) http://therealcrisp.xs4all.nl/blog/2007/01/06/broken-parsers-the-importance-of-base/ (名無しさん 2007-01-12 14:45:56 +00:00)

[66] Useful CSS Snippets - webSemantics (Mike Foskett 著, 2007-01-13 16:06:46 +09:00 版) http://www.websemantics.co.uk/tutorials/useful_css_snippets/#base

An unusual effect. IE refused to copy or highlight body content text. The issue was related to the use of the base element in the head section. Without it, copy worked. With it, IE refused to highlight the text.

Example:

<base href="someURL" />
Caused issues. The solution was to replace it with:
<base href="someURL"></base>

Other head elements may also cause this problem, though the solution should be similar.

歴史

構想

[112] Re: status. Re: X11 BROWSER for WWW ( 版) http://lists.w3.org/Archives/Public/www-talk/1991SepOct/0003.html

The base address tag is not used, nor is highlighting HP1 etc.

[113] Re: Is there a paper which describes the www protocol? ( 版) http://lists.w3.org/Archives/Public/www-talk/1992JanFeb/0000.html

Base Address

Anchors specify addresses of other documents, in a from relative to the address of the current document. Normally, the address of a document is known to the browser because it was used to access the document. However, is a document is mailed, or is somehow visible with more than one address (for example, via its filename and also via its library name server catalogue number), then the browser needs to know the base address in order to correctly deduce external document addresses.

The format of this tag is not yet specified.

[103] Tags used in HTML ( ( 版)) http://www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Tags.html#11

Anchors specify addresses of other documents, in a from relative to the address of the current document. Normally, the address of a document is known to the browser because it was used to access the document. However, is a document is mailed, or is somehow visible with more than one address (for example, via its filename and also via its library name server catalogue number), then the browser needs to know the base address in order to correctly deduce external document addresses.

The format of this tag is not yet specified. NOT CURRENTLY USED

savedas 要素案 (1992/11-1993/1)

[105] HTML DTD issues ( ( 版)) http://lists.w3.org/Archives/Public/www-talk/1992NovDec/0068.html

6. Any more thoughts on the BaseAddress tag?

[106] Re: HTML DTD issues ( ( 版)) http://lists.w3.org/Archives/Public/www-talk/1992NovDec/0072.html

Yes. It should be in. I think. I've mentioned in http://info.cern.ch/hypertext/WWW/MarkUp/Future.html

[107] Future plans for HTML ( ( 版)) http://www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Future.html

Base address

savedas
Could be a name for the tag to give the address with which the document was saved, so that relative links could be resolved even when a document is found out of context (like mailed).

[78] WWW-Talk Jan-Mar 1993: Re: HTML todo list ( ( 版)) http://1997.webhistory.org/www.lists/www-talk.1993q1/0070.html

Now, what about the SAVEDAS adddress so that from justthe content of the document hte partial UDIs can be resolved? I think that is a useful thing, and could be essentail. I will put that in as Standard.

[77] WWW-Talk Jan-Mar 1993: Re: HTML todo list ( ( 版)) http://1997.webhistory.org/www.lists/www-talk.1993q1/0072.html

Yuk, but OK for now. (I have lots to say about URLs, but until I have time to do something about it, I'll leave them be :-)

base 要素の誕生 (1993/3)

[114] base 要素が初めて登場するのは、現在確認されている中では、1993年3月10日版の仕様書と見られる >>111 です。収録されている DTD にも base 要素が含まれています。

[111] http://suika.suikawiki.org/www/2005/pre-id/html-spec-199303.pdf#page=11

8 BASE

This element allows the URL of the document itself to be recorded in situations in which the document may be read out of context. URLs within the document may be in a "partial" form relative to this base address.

Where the base address is not specified, the reader will use the URL it used to access the document to resolve any relative URLs.

The one attribute is:

HREF
the URL

[116] 2月3日付けの DTD には base 要素は含まれていません。また savedas 要素が含まれている DTD もなかったようです。

[115] その後の版である次の文書にも base 要素は引き継がれています。

[108] RFC 1866 (HTML 2.0) 5.2.2. Base Address: BASE

The optional <BASE> element provides a base address for interpreting relative URLs when the document is read out of context (see 7, "Hyperlinks"). The value of the HREF attribute must be an absolute URI.

省略可能な base 要素は、 文書が文脈外で読まれる時に相対URLを解釈するための基底番地を提供します。 href 属性の値は絶対URIでなければなりません。

実装の進展

[110] Netscape Navigator 1.0 (1995年) は既に base 要素に対応していたようです >>118。 それ以前から実装されていたかもしれません。

[39] libwwwHTML構文解析器は1996年7月20日のRelease 4.1b3でbaseを実装しました。

[75] Change History for W3C Sample Code Library ( ( 版)) http://www.w3.org/Library/User/History.html#Release50

Updated HTML parser to support BASE tag and LINK tag

[73] >>122NCSA Mosaic Unix 版 2.7b5 (1996年7月) のソースを見ると base 要素にはまだ対応していないようです。

[74] 96年にもなってまだ対応していないとは信じがたいが・・・。

[120] >>73-74 でも >>118-119 によると 1995年10月の NCSA Mosaic 2.0 以降は base 要素に対応しているらしい。

[123] 確かに >>121NCSA Mosaic 2.7 のソースには base 要素が含まれています。

[124] WinIE は 1.0 で既に base 要素に対応していたようです >>118

HTML3

[19] base 要素に id を振って、相対 URI を使う文脈でどの基底 URI (たとえば画像用の基底 URI) を使うのかを選べるようにしたらどうかという案もありました。

www-html@w3.org from May 1995: Re: <BASE> processing by browsers http://lists.w3.org/Archives/Public/www-html/1995May/0004.html

HTML4

BASE 要素 (DjVu XML)

[273] DjVu XML には HTMLbase 要素から派生した BASE 要素がありました。

HTML5

統計

[67] 今朝 (2007-05-01 02:59:14 +00:00) の #whatwg より (JST):

  • 08:15 <Hixie> about 5% of sites have 1 <base> tag, apparently
  • 08:16 <Hixie> 0.03% have 2
  • 08:16 <Hixie> 0.0017% have 3
  • 08:16 <Hixie> and a few thousand have more than 3
  • 08:18 <Hixie> so we're talking about a few million pages here
  • 08:18 <Hixie> with 2 or more <base> elements
  • 08:19 <Hixie> oh actually this was only counting _different_ values for <base>
  • 08:19 <Hixie> so a few million pages use two different values for <base>

[28]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
 <HEAD>
   <TITLE>Our Products</TITLE>
   <BASE href="http://www.example.com/products/intro">
 </HEAD>
 <BODY>
   <P>Have you seen our <A href="../cages/birds">Bird Cages</A>?
 </BODY>
</HTML>

(HTML 4 仕様書より、改)

この場合、この文書自体の URI にかかわらず、 a 要素のリンク先は http://www.example.com/cages/birds になります。

メモ

[117] 私の近況(2002年11月) ( ( 版)) http://www5e.biglobe.ne.jp/~tbs-i/kinkyo/2002/0211.html#18

[125] ( ( 版)) http://lynx.isc.org/current/CHANGES2.4

[138] ncsa-mosaic/CHANGES at master · alandipert/ncsa-mosaic ( ( 版)) https://github.com/alandipert/ncsa-mosaic/blob/master/CHANGES#L145

[139] ncsa-mosaic/CHANGES at master · alandipert/ncsa-mosaic ( ( 版)) https://github.com/alandipert/ncsa-mosaic/blob/master/CHANGES#L597

[1] This morning's work. · w3c/webappsec-csp@d669817 ( 版) https://github.com/w3c/webappsec-csp/commit/d6698170c8eede388bd351773dada7b633988be8

[2] Fix base-uri algorithm and grammar. · w3c/webappsec-csp@f4d2db1 ( 版) https://github.com/w3c/webappsec-csp/commit/f4d2db1c08534cdd1e36675cc8a93ee0c95d53ba

[3] URLs are parsed and produce records · whatwg/html@30bc255 ( 版) https://github.com/whatwg/html/commit/30bc2557105ad62881ec9670f253febbc9761b44

[4] Wire up CSP's control over the base element · whatwg/html@7bfca70 ( 版) https://github.com/whatwg/html/commit/7bfca708707e36bc2a7d5570bedc6dc4383b7676

[21] Correct URL parsing of base elements · whatwg/html@2719a51 ( 版) https://github.com/whatwg/html/commit/2719a514ebd2ee66813fb5ee92f52e99a1479e78

[7] Restrict `<base>` to ~sane schemes. · Issue #2249 · whatwg/html () https://github.com/whatwg/html/issues/2249

[23] Webmention () https://webmention.net/draft/#h-sender-discovers-receiver-webmention-endpoint

The endpoint may be a relative URL, in which case the sender must resolve it relative to the target URL according to [URL].

[24] >>23 の規定は base 要素を無視しており、 HTML Standard と矛盾しています。

[25] Add a warning about nonces and <base>. (@arturjanc著, ) https://github.com/w3c/webappsec-csp/commit/d48fd5f01143c48a8a3c40ebb169bc865e2d2123

[29] Allow customizing base URL of a shadow root · Issue #581 · w3c/webcomponents () https://github.com/w3c/webcomponents/issues/581

[30] HTML の base 要素の起源に迫ってみた