/
342.txt
194 lines (141 loc) · 12.3 KB
/
342.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
* [CODE(JS)@en[document.readyState]] 属性 (DOM)
[7] [CODE(DOMi)@en[[[Document]]]] [[オブジェクト]]の [DFN[[CODE(DOMa)@en[[[readyState]]]] [[属性]]]]は、
[[現在文書準備度]]を表します。
** 仕様書
- [8] [[Web Applications 1.0]] ([[HTML5]])
-- [10] '''<http://www.whatwg.org/specs/web-apps/current-work/complete.html#dom-document-readystate>'''
--- [CODE(JS)@en[[[document.readyState]]]]
-- [11] '''<http://www.whatwg.org/specs/web-apps/current-work/complete.html#current-document-readiness>'''
--- [[現在文書準備度]]
-- [16] <http://www.whatwg.org/specs/web-apps/current-work/complete.html#dom-xmldocumentloader-load>
--- [CODE(JS)@en[[[document.load]]]]
-- [21] <http://www.whatwg.org/specs/web-apps/current-work/complete.html#the-end>
--- [[構文解析停止]]
** 処理モデル
*** getter
[12] [CODE(JS)@en[[[document.readyState]]]] [[属性]]は[[文書]]の[[現在文書準備度]]を返さなければ[['''なりません''']]
[SRC[>>10]]。
** 現在文書準備度
[9] [[文書]]は「[DFN[[RUBYB[[[現在文書準備度]]]@en[current document readiness]]]]」という[[状態]]を持っています
[SRC[>>11]]。
- [13] [[文書]]が作られたとき、[[HTML構文解析器]]または[[XML構文解析器]]と関連付けられていれば、[[現在文書準備度]]は [DFN[[CODE(DOM)@en[[[loading]]]]]] に設定されなければ[['''なりません''']]
[SRC[>>11]]。
- [14] [[文書]]が作られたとき、 >>13 以外であれば、[[現在文書準備度]]は [DFN[[CODE(DOM)@en[[[complete]]]]]]
に設定されなければ[['''なりません''']] [SRC[>>11]]。
- [17] [CODE(JS)@en[[[document.load]]]] [[メソッド]]は読み込みの開始前に[[現在文書準備度]]を [CODE(DOM)@en[[[loading]]]] に設定します [SRC[>>16]]。
- [18] [CODE(JS)@en[[[document.load]]]] [[メソッド]]は読み込みの完了後で[[文書]]に変更が反映される直前に[[現在文書準備度]]を [CODE(DOM)@en[[[complete]]]] に設定します [SRC[>>16]]。
- [20] [[HTML構文解析器]]は[[構文解析停止]]の最初で[[現在文書準備度]]を
[DFN[[CODE(DOM)@en[[[interactive]]]]]] に設定します [SRC[>>21]]。
- [22] [[HTML構文解析器]]は [CODE(DOMe)@en[[[load]]]] [[事象]]の[[発火]]の直前に[[現在文書準備度]]を
[CODE(DOM)@en[[[complete]]]] に設定します [SRC[>>21]]。
[15] [[現在文書準備度]]が設定された時には、その [CODE(DOMi)@en[[[Document]]]]
[[オブジェクト]]において [CODE(DOMe)@en[[[readystatechange]]]] [[単純事象を発火]]しなければ[['''なりません''']]
[SRC[>>11]]。
** 関連
[19]
[[現在文書準備度]]は[[履歴探索]]の過程で [CODE(DOMe)@en[[[pageshow]]]] [[事象]]や
[CODE(DOMe)@en[[[popstate]]]] [[事象]]が[[発火]]されるかに影響します。
;; <http://www.whatwg.org/specs/web-apps/current-work/complete.html#history-traversal>
* [CODE(DOMi)@en[XMLHttpRequest]] 界面 [CODE(DOMa)@en[readyState]] 属性 (DOM)
** 仕様書
- [34] [[XHR]]
-- [35] '''<http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#dom-xmlhttprequest-readystate>'''
* [CODE(DOMe)@en[readystatechange]] 事象、[CODE(JS)@en[onreadystatechange]] 事象取扱器 (DOM)
[23] [DFN[[CODE(DOMe)@en[[[readystatechange]]]] [[事象]]]]は、 [CODE(DOMa)@en[[[readyState]]]]
[[属性]]が変化した時に[[発火]]される[[事象]]です。 [DFN[[CODE(DOMa)@en[[[onreadystatechange]]]]]]
は、 [CODE(DOMe)@en[[[readystatechange]]]] [[事象]]のための[RUBYB[[[事象取扱器]]]@en[event handler]]
([[事象取扱器内容属性]]、[[事象取扱器IDL属性]]) です。
** 仕様書
- [24] [[Web Applications 1.0]] ([[HTML5]])
-- [25] '''<http://www.whatwg.org/specs/web-apps/current-work/complete.html#handler-onreadystatechange>'''
--- [[事象取扱器]]
-- [26] <http://www.whatwg.org/specs/web-apps/current-work/complete.html#current-document-readiness>
--- [[現在文書準備度]]
- [32] [[XHR]]
-- [33] '''<http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#event-xhr-readystatechange>'''
--- [[事象]]
-- [36] <http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#dispatch-readystatechange-event>
--- [[[CODE(DOMe)@en[readystatechange]]事象発火]]
** 事象取扱器内容属性
[27] [CODE(HTMLa)@en[[[onreadystatechange]]]] [[内容属性]]はすべての [[HTML要素]]で利用可能です。
** 事象取扱器IDL属性
[28] [CODE(DOMa)@en[[[onreadystatechange]]]] [[IDL属性]]は次の[[オブジェクト]]で利用可能です。
- [29] [CODE(DOMi)@en[[[HTMLElement]]]]
- [30] [CODE(DOMi)@en[[[HTMLDocument]]]]
- [31] [CODE(DOMi)@en[[[Window]]]]
* メモ
[1] [[Opera]] の <script>.onreadystatechange はなんかおかしい。呼ばれるタイミングが IE と違う?
[2] [CITE@ja[Dynamic HTML(クライアントサイドスクリプトやIE固有のプログラム要素も含む)]] ([TIME[2007-03-18 16:34:07 +09:00]] 版) <http://www.rody.dev-asp.net/memo/dhtml/index.html>
>絶対にそうだとは言えないが、調べたところでは以下のような関係だった。
=子ウィンドウを持つウィンドウは全ての子ウィンドウのreadyStateが"complete"にならないと、自ウィンドウのreadyStateは"complete"にならない。また、正確にはreadyStateが"complete"でdocument.onReadyStateChangeイベントを抜けた時に、完全に"complete"したとみなす。
= window.onloadイベントは自ウィンドウのreadyStateが"complete"になった後、発生する(正確な判断は1と同様)。
=兄弟ウィンドウ同士は非同期で動作する。
=(重要)1及び2からウィンドウが"complete"する順番は子ウィンドウから正しく"complete"する事になるが、各ウィンドウのonloadイベントに関しては必ずしも同期しているとは限らない。親ウィンドウのonloadが子ウィンドウのonloadよりも先に走る可能性もタイミングによっては有り得る。
= 他のファイルをインクルードしているものに関しては分からないが、 readyStateが"complete"になるのはhtmlタグ内のドキュメントが読み込み終わった時ではなくて、そのファイル全体のソースが読み込み終わった時に発生しているっぽい(どっちにしろhtmlタグ内に全て書いていれば関係ないが)。
>
補足:もし、子ウィンドウのロードを非同期で(同時に)行い、各ウィンドウの初期処理を正確に順番通りに行いたいためにトップウィンドウのonReadyStateChangeイベント、もしくはonloadイベントで子ウィンドウの初期処理を順番に行うのであれば、子ウィンドウのonReadyStateChangeイベントもしくはonloadイベントに初期処理を入れるべきではない。トップウィンドウからの初期処理関数呼び出しと、各子ウィンドウのonloadイベントに初期処理が記述されている場合、どちらの初期処理が先に走るかは不定。よって、もう片方の初期処理が完了している事を前提でコーディングすると、処理が走るタイミングによっては未初期化でエラーが発生するかも。
[3] [CITE[外部JavaScriptの動的ロード - 0x集積蔵]] ([TIME[2009-02-03 20:38:44 +09:00]] 版) <http://d.hatena.ne.jp/os0x/20080827/1219815828>
[4]
[CITE[document.readyState - 素人がプログラミングを勉強するブログ]] ([TIME[2009-02-08 18:12:23 +09:00]] 版) <http://d.hatena.ne.jp/javascripter/20090125/1232880728>
[5] [CITE[IEメモリリークの最後の壁はAjaxのonreadystatechangeやった!! - SEの行き着くところ…]] ([TIME[2009-02-03 20:40:56 +09:00]] 版) <http://d.hatena.ne.jp/AWAWA/20071207/1197036423>
[6] [CITE[外部JavaScriptの動的ロード - 0x集積蔵]] ([TIME[2009-02-03 20:38:44 +09:00]] 版) <http://d.hatena.ne.jp/os0x/20080827/1219815828>
[37] [CITE@en[Web Applications 1.0 r5501 document.readyState should be updated after csalling document.open().]]
( ([TIME[2010-09-26 05:45:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=5500&to=5501>
[38] [CITE[IRC logs: freenode / #whatwg / 20101220]]
( ([TIME[2011-01-04 21:33:33 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20101220>
[39] [CITE@en[Web Applications 1.0 r6543 Add script.readyState and fire 'readystatechange' in some cases. Not 100% IE compatible because IE is pretty inconsistent here. Should be compatible with legacy content though, both in browsers that do script prefetch and those that don't.]]
( ([TIME[2011-09-08 06:54:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=6542&to=6543>
[40] [CITE[IRC logs: freenode / #whatwg / 20110907]]
( ([TIME[2011-09-08 21:53:10 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20110907>
[41] [CITE['''['''whatwg''']''' readystatechange for SCRIPT]]
([TIME[2011-09-09 18:44:49 +09:00]] 版)
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-September/033146.html>
[42] [CITE@en[Web Applications 1.0 r6550 Revert r6543 and instead move onreadystatechange to be only on Document.]]
( ([TIME[2011-09-10 07:44:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=6549&to=6550>
[43] [CITE@en[HTML5 Tracker]]
([TIME[2011-10-15 15:27:33 +09:00]] 版)
<http://html5.org/tools/web-apps-tracker?from=6688&to=6689>
[44] [CITE@en[Web Applications 1.0 r6882 Make the readyState change, the 'readystatechange' event, and the 'load' event all happen synchronously in the same task so that you can check readyState to know whether you still have to attach an 'onload' event handler.]]
( ([TIME[2012-01-10 09:08:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=6881&to=6882>
[45] [CITE[''''''[''''''whatwg'''''']'''''' Readiness of script-created documents]]
( ([TIME[2012-01-14 12:23:16 +09:00]] 版))
<http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-January/034363.html>
[46] [CITE[IRC logs: freenode / #whatwg / 20120313]]
( ([TIME[2012-03-17 20:31:54 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20120313>
[47] [CITE[''''''[''''''whatwg'''''']'''''' Readiness of script-created documents]]
( ([TIME[2012-06-12 08:10:52 +09:00]] 版))
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-June/036356.html>
[48] [CITE@en[Web Applications 1.0 r7169 Make 'abort the parser' fire some readystatechange events for more consistency. Slightly expand on how little XSLT/HTML interactions are defined. Rename 'cookie-free' to 'cookie-averse' for clarity.]]
( ([TIME[2012-07-11 04:15:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=7168&to=7169>
[49] [CITE[''''''[''''''whatwg'''''']'''''' Proposal for readyState behavior]]
( ([TIME[2012-07-11 07:30:22 +09:00]] 版))
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-July/036592.html>
[50] [CITE[''''''[''''''whatwg'''''']'''''' DOMContentLoaded, load and current document readiness]]
( ([TIME[2012-08-30 01:12:43 +09:00]] 版))
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-August/037045.html>
[51] [CITE[''''''[''''''whatwg'''''']'''''' Proposal for readyState behavior]]
( ([TIME[2012-08-30 01:12:43 +09:00]] 版))
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-August/037042.html>
[52] [CITE[''''''[''''''whatwg'''''']'''''' Readiness of script-created documents]]
( ([TIME[2012-08-30 01:12:43 +09:00]] 版))
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-August/037040.html>
[53] [CITE@en[Web Applications 1.0 r7299 Try to make aborting parsing and regular ending of parsing slightly more similar. Also, emphasise the importance of stress in the definition of <em>. (Sorry for the mixed checkin.)]]
( ([TIME[2012-08-31 02:46:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=7298&to=7299>
[54] [CITE@en[Web Applications 1.0 r7781 Make document.readyState explicitly an enum, not that that has any real effect.]]
( ([TIME[2013-03-30 03:13:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=7780&to=7781>
[55] [CITE@en[Web Applications 1.0 r8334 Define img.complete to include broken images, per implementations]]
( ([TIME[2013-12-07 04:10:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=8333&to=8334>
[56] [CITE@en[Turn state into a proper concept · 35c958e · whatwg/xhr]]
( ([TIME[2014-10-18 14:53:51 +09:00]] 版))
<https://github.com/whatwg/xhr/commit/35c958e4ad2b7ee43020605b66e45322c16e6ede>