/
582.txt
167 lines (121 loc) · 6.65 KB
/
582.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
* [CODE(DOMe)@en[load]] イベント
[20] [CODE(DOMe)@en[[[load]]]] [[イベント]]は、様々な場面で[[発火]]されます。
次の各項を参照してください。
[FIG(list short)[
- [[stops parsing]]
- [CODE(JS)@en[[[document.load]]]]
- [10] [CODE(JS)@en[[[window.open]]]]
- [14] [CODE(HTMLe)@en[[[iframe]]]]/[CODE(HTMLe)@en[[[frame]]]]
- [CODE(HTMLe)@en[[[embed]]]]
- [CODE(HTMLe)@en[[[object]]]]
- [[スクリプトブロックの実行]]
]FIG]
[22] [[dispatch]] での[[イベント親]]の決定では、特別な扱いがされることもあります。
* [CODE(DOMa)@en[onload]] 属性
[1] [[HTML]] の [CODE(HTMLe)[[[body]]]] 要素と
[CODE(HTMLe)[[[frameset]]]] 要素の [DFN[[CODE(HTMLa)[onload]] 属性]]は、
[[UA]] が[[窓]]またはすべての[[フレーム]]を読込み終えた時に発生する[[事象]]に関する[[内在事象]]属性です。
[2] 仕様書:
- [[HTML 4]]
-- [CODE(HTMLa)[onload]] 属性
<IW:HTML4:"interact/scripts.html#adef-onload">
** 代替
[3] 内在事象属性は[[表現と構造の分離]]の原則に反するので、
好ましくないと考える人もいます。また、 [[DOM 0]]
に基づく古い設計です。
代わりに、 [CODE(HTMLe)[[[script]]]] 要素などにより関連付けたスクリプト内で
[[DOM 2]] 以上の[[事象]]に関するメソッド等が利用できます。
DOM 水準2 や DOM 水準 3 の HTML 事象モジュールはこの属性に対応する
DOM の事象 [CODE(DOM)[[[load]]]] を用意しています。
[[#comment]]
** 属性値
[4] この属性の値は [CODE(SGML)[%[[Script]]]] です。 [[SGML]]
的には [CODE(SGML)[[[CDATA]]]] です。[[スクリプト言語]]は、
[CODE(HTTP)[[[Content-Script-Type]]]] によります。
[5] この属性は省略可能です。
[[#comment]]
** 他との関係
[6] この属性に対応する DOM の事象は [CODE(DOM)[[[load]]]]
です。そちらもあわせてごらんください。
[7] 反対の意味の [CODE(HTMLa)[[[onunload]]]] 属性もあります。
[[#comment]]
** 例
[8] 新しい窓の読込み時の動作を規定する例 (JavaScript) [SRC[HTML 4 18.2.3]]
[PRE(HTML)[
<SCRIPT type="text/javascript">
function my_onload() {
. . .
}
var win = window.open("some/other/URI")
if (win) win.onload = my_onload
</SCRIPT>
]PRE]
なんで HTML 4 仕様書がわざわざこんな例を [Q[interesting]]
とかいって取り上げているのか謎です。 DOM 水準 0
では [CODE(JS)[window.onload]] で [CODE(HTMLe)[body]]
要素の [CODE(HTMLa)[onload]] に access できるのでしょうか?
新しい窓の読込み時の動作を規定する例 (Tcl) [SRC[HTML 4 18.2.3]]
[PRE(HTML)[
<SCRIPT type="text/tcl">
proc my_onload {} {
. . .
}
set win [window open "some/other/URI"]
if {$win != ""} {
$win onload my_onload
}
</SCRIPT>
]PRE]
それに、 [CODE(DOMm)[[[open]]]] したあとに [CODE(DOMa)[onload]]
を設定しても、場合によっては既に読込みが終わっているのではないかと思うのですが、
DOM 水準 0 ブラウザの実装との絶妙なバランスによって正しく動作していたのでしょうかねぇ。
* 歴史
[9]
[CITE[Internet Explorer の JavaScript の脆弱性に関する注意喚起]] <http://www.jpcert.or.jp/at/2005/at050010.txt>
([[名無しさん]] [WEAK[2005-11-23 00:41:40 +00:00]])
[11]
[CITE[Bug 225244 – onload attribute not allowed in HTML tags other then BODY and FRAMESET]] ([CODE[2007-02-28 19:55:36 +09:00]] 版) <https://bugzilla.mozilla.org/show_bug.cgi?id=225244>
([[名無しさん]])
[12]
[CITE[A blog? with Σαιτω - onload と Safari]] ([CODE[2007-06-15 18:42:57 +09:00]] 版) <http://d.hatena.ne.jp/saiton/20070615/1181861435>
([[名無しさん]] [WEAK[2007-06-15 12:36:39 +00:00]])
[13]
[CITE[Safari and page load timing]] ([CODE[2007-06-16 11:18:57 +09:00]] 版) <http://www.howtocreate.co.uk/safaribenchmarks.html>
([[名無しさん]] [WEAK[2007-06-16 02:24:23 +00:00]])
** HTML5
[21] [CODE(HTMLe)@en[[[script]]]] [[要素]]の [CODE(HTMLa)@en[[[event]]]]
[[属性]]は、正式に[[廃止]]されました。その値 [CODE[[[onload]]]]
の扱いは[[スクリプトの準備]]を参照。
[15] [CITE[''''''[''''''whatwg'''''']'''''' Load events fired during onload handlers]]
( ([TIME[2012-11-30 05:14:27 +09:00]] 版))
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-November/038192.html>
[16] [CITE@en[Bug 23508 – Browsers want to know when a page's scripts have finished 'loading', even if the scripts aren't delaying the 'load' event any more (e.g. they do computation on startup)]]
( ([TIME[2013-10-14 22:58:35 +09:00]] 版))
<https://www.w3.org/Bugs/Public/show_bug.cgi?id=23508>
[17] [CITE@en[Web Applications 1.0 r8287 Clean up how we describe the 'delay the load event' logic for loading nested iframes]]
( ([TIME[2013-11-16 06:20:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=8286&to=8287>
[18] [CITE@en[Web Applications 1.0 r8407 Make nested browsing contexts delay the load event of their parent while they're loading]]
( ([TIME[2014-01-18 07:44:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=8406&to=8407>
[19] [CITE@en-US[svg2: changeset 697:22d3225a3ffb]]
( ([TIME[2014-08-24 03:07:38 +09:00]] 版))
<https://dvcs.w3.org/hg/svg2/rev/22d3225a3ffb491aaa94e54bb709668ce005e2f6>
[23] [CITE@en[Regression fix: run iframe load event steps immediately]]
([[annevk]]著, [TIME[2018-01-16 19:23:55 +09:00]])
<https://github.com/whatwg/html/commit/3784c5375a36e19373982984ff761b491125a5da>
[24] [CITE@en["iframe load event steps" are run in parallel, but that seems really bad · Issue #3357 · whatwg/html]]
([TIME[2018-01-18 15:49:23 +09:00]])
<https://github.com/whatwg/html/issues/3357>
[25] [CITE@en[Regression fix: run iframe load event steps immediately by annevk · Pull Request #3359 · whatwg/html]]
([TIME[2018-01-18 15:50:24 +09:00]])
<https://github.com/whatwg/html/pull/3359>
[26] [CITE@en[Make <frame> fire load synchronously with "completely loaded"]]
([[annevk]]著, [TIME[2018-02-22 20:11:33 +09:00]])
<https://github.com/whatwg/html/commit/16de123059bd4b3660677fb4fdc03e2053815482>
[27] [CITE@en[frame and iframe have different load-event-firing behaviors · Issue #3492 · whatwg/html]]
([TIME[2018-02-24 19:33:37 +09:00]])
<https://github.com/whatwg/html/issues/3492>
[28] [CITE@en[Make <frame> fire load synchronously with "completely loaded" by annevk · Pull Request #3495 · whatwg/html]]
([TIME[2018-02-24 19:34:02 +09:00]])
<https://github.com/whatwg/html/pull/3495>