-
Notifications
You must be signed in to change notification settings - Fork 4
/
296.txt
91 lines (74 loc) · 5.53 KB
/
296.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
* 仕様書
[REFS[
- [6] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2015-04-25 04:40:19 +09:00]] 版) <https://html.spec.whatwg.org/#prompt-to-unload-a-document>
]REFS]
* 処理
[7] [DFN[[[prompt to unload a document]]]] は、次のようにしなければ[['''なりません''']]
[SRC[>>6]]。
[FIG(steps)[
= [[文書]]の[[イベントループ]]の [[termination nesting level]] を一度[[インクリメント]]します。
= [[文書]]の [[ignore-opens-during-unload counter]] を一度[[インクリメント]]します。
= [[イベント]]を[[発火]]します。
[FIG(list members short)[
[FIGCAPTION[
[[イベント]]
]FIGCAPTION]
:[[インターフェイス]]:[CODE(DOMi)@en[[[BeforeUnloadEvent]]]]
:[[イベント名]]:[CODE(DOMe)@en[[[beforeunload]]]]
:[[trusted]]:[[真]]
:[[bubbles]]:[[偽]]
:[[取り消し可能]]:[[真]]
:[[対象]]:[[文書]]の [CODE(DOMi)@en[[[Window]]]]
]FIG]
= [[文書]]の[[イベントループ]]の [[termination nesting level]] を一度[[デクリメント]]します。
= [[ストレージミューテックス]]を解放します。
= 先の[[イベント]]の[[発火]]でいずれかの[[イベントリスナー]]が実行されていたらなら、
[[文書]]の [[''salvageable'']] を[[偽]]に設定します。
= 先の[[イベント]]オブジェクトの [CODE(DOMa)@en[[[returnValue]]]]
が[[空文字列]]以外であるか、先の[[イベント]]が[[取り消し]]されていたなら、
[[利用者]]に対して unload を望むか確認する[['''べきです''']]。
== この確認時に、 [CODE(DOMa)@en[[[returnValue]]]] の値、またはその先頭 (例えば1024文字分)
を示して構いません。
== [[利用者]]の応答があるまで、 [[pause]] します。
== [[利用者]]が unload を望まないと応答したら、
[DFN[[[refused to allow the document to be unloaded]]]] フラグを設定します。
= これが再帰呼び出しでないなら、
== [[文書]]の[[子孫閲覧文脈のリスト]]の各[[閲覧文脈]]について、
=== [[閲覧文脈]]の[[活性文書]]について [[prompt to unload a document]] を再帰的に呼び出します。
=== その結果が [[refused to allow the document to be unloaded]] なら、
[[refused to allow the document to be unloaded]] フラグを設定し、
各[[閲覧文脈]]についての処理を終えて次に進みます。
=== [[閲覧文脈]]の[[活性文書]]の [[''salvageable'']] が[[偽]]なら、
[[文書]]の [[''salvageable'']] も[[偽]]に設定します。
= [[文書]]の [[ignore-opens-during-unload counter]] を一度[[デクリメント]]します。
= [[refused to allow the document to be unloaded]] かどうかを返します。
]FIG]
[8] [[prompt to unload a document]] は [[navigate]] から呼び出されます。
;; [10] [[素片識別子へのスクロール]]しかしない場合は呼び出されませんが、
[[fetch]] を行う場合などは (最終的に[[ダウンロード]]などに至るとしても、
それが決まる前に) 呼び出されます。詳しくは [[navigate]] を参照。
[9] [[prompt to unload a document]] の実行中は、 [[navigate]] は何もしません。
つまり [CODE(DOMe)@en[[[beforeunload]]]] [[イベント]]内ではページ遷移の開始が抑制されます。
;; [[navigate]] を参照。なお ⊿ を指定した[[履歴の探索]]は抑制されませんが、
実際の処理は別の[[タスク]]を[[タスクキュー]]に入れる形で実行されるので、
[CODE(DOMe)@en[[[beforeunload]]]] [[イベント]]内で同期的にページ遷移が開始されることはありません。
[11] [[prompt to unload a document]] は ⊿ を指定した[[履歴の探索]]や、
[CODE(JS)@en[[[window.open]]]] や、[[閲覧文脈を閉じる]]際にも呼び出されます。
[12] [[prompt to unload a document]] が呼び出された場合、 refuse
されていなければ、その後 [[unload a document]] が呼び出されることになります。
* 歴史
[1] [CITE[Re: salvaging work while navigating away from a web app -- onunload="confirm('save before quitting?')]] ([[Ian Hickson]] 著, [TIME[2008-12-12 08:55:08 +09:00]] 版) <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/17107>
[2] [CITE@en[IEでのonBeforeUnload の挙動 | Inside ASCADE]] ([TIME[2009-02-20 05:46:35 +09:00]] 版) <http://inside.ascade.co.jp/node/58>
><a> タグの href で javascipt を呼び出した場合に location を変化させない(つもり)にもかかわらず、onBeforeunload イベントが発生したことです。ちなみにFirefoxではこの場合にイベントは発生しません。
>
- 多少仕様の記述と異なるが大体MSDNのドキュメント通り
- href="javascript:xx" でonBeforeunload が発生するのは少し困る
- document.close ではonBeforeunload が発生しないが別に困らない
[3] [CODE(DOMe)@en[[[beforeunload]]]] 内で [CODE(HTMLe)@en[[[img]]]] により [[fetch]] を行うと、
[[Chrome]] と [[IE10]] では実際にアクセスが発生しますが、 [[Firefox]] では発生しません。 [TIME[2013-07-04T03:05:58.500Z]]
[4] [CITE@en[Web Applications 1.0 r8282 OnBeforeUnloadEventHandler is supposed to allow null return values (and some markup error fixes, oops)]]
( ([TIME[2013-11-14 07:45:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=8281&to=8282>
[5] [CITE[IRC logs: freenode / #whatwg / 20150115]]
( ([TIME[2015-01-16 11:47:48 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20150115#l-693>