PopStateEvent

PopStateEvent

仕様書

直列化済み状態

[16] 直列化済み状態 (serialized state) (旧状態オブジェクト (state object) ) は、利用者インターフェイスの状態を表すオブジェクトです >>15

[17] 状態オブジェクトは、セッション履歴エントリー中に設定されることがあります。

[18] 著者pushStatereplaceState により状態オブジェクトを指定できます。

[19] 著者popstate イベントにより状態オブジェクトを受け取ることができます。

history.state 属性 (DOM)

[22] History インターフェイスstate IDL属性取得器は、 次のようにしなければなりません >>21

  1. [25] 文脈オブジェクト文書完全に活性なら、
    1. [23] SecurityError 例外投げ、ここで停止します。
  2. [26] 文脈オブジェクトstate を返します。

[24] History オブジェクトは、 state を持ちます。 初期値は null です >>21

[27] 履歴の探索pushState/replaceState で値が設定されます。

pushState メソッド、replaceState メソッド

[29] History インターフェイスpushState メソッドreplaceState メソッドは、 次のようにしなければなりません >>28

  1. [57] データを、第1引数を必須の any として解釈した結果に設定します。
  2. [58] 題名を、第2引数を必須の USVString として解釈した結果に設定します。
  3. [59] URL を、第3引数を省略可能な DOMString? として解釈した結果に設定します。省略時の既定値は、 null とします。
  4. [60] 文書を、文脈オブジェクト文書に設定します。
  5. [83] 文書完全に活性でなければ、
    1. [61] SecurityError 例外を投げ、ここで停止します。
  6. [62] 利用者エージェントの判断で、ここで停止して構いません。

    [63] 利用者動作によって起動された場合以外の時や、 短時間で連続して実行された時、 データが巨大すぎる場合などに、 本メソッド呼び出しを無視できます。

  7. [64] 直列化済みデータを、 StructuredSerializeForStorage (データ, 文脈オブジェクトRealm) の結果に設定します。例外が投げられたら、それを再度投げ、ここで停止します。
  8. [70] 現在のURLを、文脈オブジェクト文書URLに設定します。
  9. [65] URLnull 以外なら、
    1. [67] 新URL を、URL文書に対して構文解析した結果に設定します。
    2. [66]
      ... のいずれかの場合、
      1. [71] SecurityError 例外投げ、ここで停止します。
  10. [51] それ以外の場合、
    1. [52] 新URLを、文書閲覧文脈セッション履歴現在エントリーURL に設定します。
  11. [37] URLおよび履歴更新手順群を実行します。
    文書
    文書
    新URL
    新URL
    直列化済みデータ
    直列化済みデータ
    題名
    題名
    状態pushフラグ
    本メソッドは pushState であるか否か
  12. [78] 文脈オブジェクトstate を、 StructuredDeserialize (直列化済みデータ, 文脈オブジェクトRealm) の結果に設定します。 例外投げられたら、 文脈オブジェクトstate を、 null に設定します。
  13. [79] 現在エントリー文書最新エントリーは、現在エントリーとします。
  14. [80] 現在のURL新しいURLが異なるなら、
    1. [81] webNavigation API の onHistoryStateUpdated を呼び出します。 遷移型遷移修飾子は適宜設定します。現在時刻も引き渡します。 仕様書なし
[53] >>50同じ起源かどうかの判断ではないので、 userinfo の有無や値も (あれば) 判定基準となります。

[30]メソッド文書の番地を変更することができるものですが、 文書の起源実効スクリプト起源文書のドメインを変更することはできません。 この意味で同一起源ポリシーを緩和するものではありません。更に、 document.domain を使っても変更可能な範囲を拡大することはできません。

[31] 文書の起源ではなく文書の番地起源が問題となりますから、 文書の起源同じ起源であっても about:blankdata: URL文書の番地となっている時、 http:https:URL に変更することはできません。 この意味で同一起源ポリシーより制限が厳しいと言うこともできますが、 両メソッドの趣旨が文書の番地を変更するものですから、当然の制約でもあります。

[32] 砂箱によって異なる起源で動作するスクリプト素片識別子以外を変更することもできません。

[33] >>31>>32 は、文書の起源文書の番地起源の両方と同じ起源URL には変更できる、と言い換えられます。

[35] 利用者エージェントは、 pushState の濫用を防ぐため、 タイマーからの呼び出しや利用者の明確な操作によらないイベントリスナーからの呼び出し、短時間での連続呼び出しを無視したほうが良いかもしれません >>34

popstate イベント

[40] popstate イベントは、履歴の探索により history.state の値が変更された時に発火されます。

[42] PopStateEvent インターフェイス >>41 は、 popstate イベントと共に用いられます。 文書環境ワーカー環境晒されています >>41

[44] PopStateEvent インターフェイスは、 他の Event インターフェイス同様のコンストラクターを持ちます >>41。 初期化のための辞書は PopStateEventInit です >>41

[43] PopStateEvent インターフェイスは、 Event インターフェイス継承しています >>41PopStateEventInit 辞書は、 EventInit 辞書継承しています >>41

[45] PopStateEvent インターフェイスおよび PopStateEventInit 辞書は、any 型の読み取り専用IDL属性 stateを持ちます >>41。 初期値は null です >>41履歴の探索popstate イベント発火される時は、状態オブジェクト (なければ null) が設定されます。

利用者インターフェイス

[36] 履歴を参照。

乱用

[48] 悪意のある著者が、 利用者の正常な履歴操作を妨害するために pushState/popstate を使うことがあります >>47。 例えば戻るボタンを無効化するための手段として、 あたかも正当な技法のように紹介する悪い人がいます。

[96] Webブラウザーはそうした悪用を防ぐための対策を講じることができ (>>35)、 利用者を保護することが期待されています。 最近の Webブラウザー履歴インターフェイスは、 複数まとめて戻るような機能が提供されていたりもします。 履歴


[86] ページをスクロールしていくだけで、 勝手にその位置を表す URL (例えば記事に投稿されたコメントの URL や、章節を表す URL、全体の URLパス素片識別子が違うもの) に replaceState で置き換えていくサイトがあります。

この機能は一見便利そうですが、 URL共有しようとする読者が思っていもいない URL を渡してしまうので、 不便です。やめてほしいです。

歴史

[1] History management for "Ajax" applications - Anne’s Weblog (2007-08-10 19:42:23 +09:00 版) http://annevankesteren.nl/2007/08/ajax-history (名無しさん 2007-08-10 16:32:50 +00:00)

[2] Re: several messages about pushState() and related ideas (Ian Hickson <ian@...> 著, 版) http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/11643

[3] Web Applications 1.0 r5964 12277 ( ( 版)) http://html5.org/tools/web-apps-tracker?from=5963&to=5964

[4] Manipulating the browser history - MDC ( 版) https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history

[5] [whatwg] Asynchronous history navigation and some inconsistencies ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-June/036505.html

[6] IRC logs: freenode / #whatwg / 20120629 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20120629

[7] Interview with Ian Hickson, HTML editor | HTML5 Doctor ( ( 版)) http://html5doctor.com/interview-with-ian-hickson-html-editor/

[8] Issue 45361 - chromium - history.pushState does not update http referrer - An open-source project to help move the web forward. - Google Project Hosting ( ( 版)) https://code.google.com/p/chromium/issues/detail?id=45361

[9] Bug 40027 – location.href and outgoing referrer not updated properly by pushState/replaceState ( ( 版)) https://bugs.webkit.org/show_bug.cgi?id=40027

[10] 622088 – XHR referer header is not modified with history.pushState ( ( 版)) https://bugzilla.mozilla.org/show_bug.cgi?id=622088

[11] History (Windows) ( ( 版)) http://msdn.microsoft.com/en-us/library/ie/hh920758(v=vs.85).aspx

[12] [whatwg] Proposal: Allow disabling of default scroll restoration behavior (Majid Valipour 著, 版) https://lists.w3.org/Archives/Public/public-whatwg-archive/2015Mar/0070.html

[13] Customizing Scroll Restoration - Google ドキュメント ( 版) https://docs.google.com/a/chromium.org/document/d/1Tiu8PjvBtNOAgeh6yrs7bOrXxQcavQLiNtRJ_ToLlVM/edit?pli=1#heading=h.j26hb4a80gnf

[14] Re: [whatwg] Proposal: Allow disabling of default scroll restoration behavior (Ian Hickson 著, 版) https://lists.w3.org/Archives/Public/public-whatwg-archive/2015Apr/0075.html

[20] defunkt/jquery-pjax ( ( 版)) https://github.com/defunkt/jquery-pjax

[38] IRC logs: freenode / #whatwg / 20090818 ( 版) http://krijnhoetmer.nl/irc-logs/whatwg/20090818#l-118

[39] [whatwg] history.popstate in Firefox4 ( ( 版)) http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-January/034570.html

[46] Add scroll restoration preference to history traversal · whatwg/html@dd6a34e ( 版) https://github.com/whatwg/html/commit/dd6a34ec3c191ee1968a0fc8d174b4ce3b615916

[49] Fix #521: all URLs can be relative · whatwg/html@e99f0bd ( 版) https://github.com/whatwg/html/commit/e99f0bd112e0216698bf9397b64b3f8064995756

[54] Write structured clone algorithm in terms of ECMAScript · whatwg/html@bfb960c ( 版) https://github.com/whatwg/html/commit/bfb960c938580c95e77365e614218b952f96375b

[55] Editorial: define Event attribute defaults through IDL · whatwg/html@0be0229 ( 版) https://github.com/whatwg/html/commit/0be02299f128cbb7c65a7ce259fdd838fd44a4b5

[56] Make it explicit that user agents can ignore replaceState/pushState · whatwg/html@38139b4 ( 版) https://github.com/whatwg/html/commit/38139b40d9b808c9bc8646df74c5c075ad7584fe

[72] チェンジセット 198687 – WebKit ( 版) https://trac.webkit.org/changeset/198687/

[73] Bug 155901 – Soften push/replaceState frequency restrictions ( 版) https://bugs.webkit.org/show_bug.cgi?id=155901

[74] Rename document's address to URL ( (annevk著, )) https://github.com/whatwg/html/commit/16dd60cfb1cbd4ea3dcacc91f58b368b021ded33

[75] Use USVString for all URLs ( (domenic著, )) https://github.com/whatwg/html/commit/018b983b77b2cd908f6d00100e7e0abe893dd2c3

[76] [giow] (2) Make sure to fire the relevant events on the Window object… ( (Hixie著, )) https://github.com/whatwg/html/commit/afdba55e4ae45f4c9d42c00902da1a0df7381aad

[82] Use relevant settings object for pushState/replaceState URL parsing (domenic著, ) https://github.com/whatwg/html/commit/b568cf93ac374c440e29e01a2619365dde7c45c8

[84] Use the associated document for pushState/replaceState's origin check (domenic著, ) https://github.com/whatwg/html/commit/60f84adcae2d252fc63afa6b65686a4590d28734

[85] PopStateEvent/HashChangeEvent/PageTransitionEvent are Window-only (zcorpan著, ) https://github.com/whatwg/html/commit/dec1a5809e15d29592a66147ce2bed5018121b5f

[88] Breaking: refactor structured clone into serialize/deserialize (domenic著, ) https://github.com/whatwg/html/commit/97d644c97335956610a31e8ad98d1a388c063e84

[89] Serializing and deserializing SharedArrayBuffer (annevk著, ) https://github.com/whatwg/html/commit/b3f8779c76de7718bc970fdbccda18a5164d2f98

[90] Remove more types from document.createEvent() (ayg著, ) https://github.com/whatwg/dom/commit/5a532da58455e55b1e611161b72224d083fee7d4

[91] Make popstate and hashchange events not bubble (foolip著, ) https://github.com/whatwg/html/commit/85e1e724cf09574dba47d5eae689bdb5b7fd6502

[92] Let the popstate and hashchange events not bubble by foolip · Pull Request #3737 · whatwg/html () https://github.com/whatwg/html/pull/3737

[93] document.open() can make a document's URL go out of sync with its history entry · Issue #3885 · whatwg/html () https://github.com/whatwg/html/issues/3885

[94] document.open() simplifications, part 2 by TimothyGu · Pull Request #3946 · whatwg/html () https://github.com/whatwg/html/pull/3946

[95] Editorial: Factor out history.push/replaceState() steps (TimothyGu著, ) https://github.com/whatwg/html/commit/f42dcf0bf2ebf86bc5ca79aecea098a8fed6cf3e

[77] Editorial: Factor out history.push/replaceState() steps (TimothyGu著, ) https://github.com/whatwg/html/commit/f42dcf0bf2ebf86bc5ca79aecea098a8fed6cf3e

[87] リンクをクリックするだけでiOSデバイスが再起動してしまうWebサイト | スラド アップル, https://apple.srad.jp/story/16/01/29/0549256/