Location (DOM)

Location オブジェクト (DOM)

仕様書

Location オブジェクト

[23] Location オブジェクトは、 閲覧文脈活性文書文書の番地を表します。 また、閲覧文脈セッション履歴を変更する API を提供します。 >>12

DefaultProperties
作成時点での自身のプロパティーのリストです >>12
文書
当該オブジェクトが関連付けられた文書です。
関係するDocument (relevant Document)
文書閲覧文脈活性文書です >>12
URL (url)
関係するDocument文書の番地です >>12
祖先起源群配列
ancestorOrigins IDL属性の値です。

[7] URLUtils としての動作は location.href を参照。

メンバー

[1]

WorkerLocation インターフェイス (DOM)

[10] WorkerLocation オブジェクトは、 WorkerGlobalScope オブジェクトURL を表します。

location IDL属性

[21] window.location IDL属性取得器は、 次のようにしなければなりません >>12

  1. [22] 文脈オブジェクトLocationを返します。

[16] document.location IDL属性取得器は、 次のようにしなければなりません >>12

  1. [17] 文脈オブジェクト完全に活性なら、
    1. [18] 文脈オブジェクト関連大域オブジェクトLocationを返します。
  2. [19] それ以外なら、
    1. [20] null を返します。

[85] window.locationdocument.locationPutForwards=href です。 >>12 つまり、 window.location = urlwindow.location.href = url と等価です。

[88] なお location.hrefstringifier として定義されています。 従って Location オブジェクトの toString メソッドlocation.href取得器と等価です。 つまり、 window.location文字列連結すると location.href とみなされます。

[86] 実際の WebページJavaScript では window.location やその省略形の location を使う場合が多く、 document.location はあまり使われません。
[87] window.location = urllocation = url はわかりにくいので、 window.location.href = url と書くことが多いです。

[89] 先日 SNSwindow.locationsetterHTML Standard に規定がないとか解説している人を見かけましたが、 誤りです。 初期の初期からしっかり規定されています。 そのように仕様書を引いてもっともらしいことを書いていても、 正確に読み込んでいるとは限らないので注意しましょう。

文脈

[13] Window オブジェクトは、 固有の Location オブジェクトを持ちます。 Window オブジェクトの作成時に Location オブジェクトが割り当てられます。 >>12

[14] document.openLocation オブジェクトは新しいものに差し替えられるとされていましたが、 その規定は削除されています。

作成

[24] Location オブジェクトの作成は、次のようにします >>12

  1. [25] オブジェクトを、新しい Location プラットフォームオブジェクトに設定します。 オブジェクトDefineOwnProperty を実行して次の通りメンバーを作成します。
    name
    名前 (第1引数)
    Value
    Value
    Writable
    Writable
    Enumerable
    Enumerable
    Configurable
    Configurable
    name
    toString
    Value
    %ObjProto_toString%
    Writable
    false
    Enumerable
    false
    Configurable
    false
    name
    toJSON
    Value
    undefined
    Writable
    false
    Enumerable
    false
    Configurable
    false
    name
    valueOf
    Value
    %ObjProto_valueOf%
    Writable
    false
    Enumerable
    false
    Configurable
    false
    name
    @@toPrimitive
    Value
    undefined
    Writable
    false
    Enumerable
    false
    Configurable
    false
  2. [26] オブジェクトDefaultProperties を、 オブジェクトOwnPropertyKeys を実行した結果に設定します。
  3. [27] オブジェクトを返します。

[31] 更に、 祖先起源群配列を設定しなければなりません

異なる起源からのアクセス

[42] Location は、同じ起源でなくてもアクセスできる例外的なオブジェクトです。 (そのような性質を持つのは他に WindowProxy だけです。)

[43] 同じ起源からアクセスした時と、それ以外からアクセスした時とで、 動作がかなり変わります。

[44] JavaScript内部メソッドは次のように動作しなければなりません >>12

method
内部メソッド
params
引数
same
IsPlatformObjectSameOrigin(this)
cross
IsPlatformObjectSameOrigin(this)
method
[60] GetPrototypeOf
same
! OrdinaryGetPrototypeOf(this) を返します。
cross
null を返します。
method
[61] SetPrototypeOf
same
を返します。
cross
を返します。
method
[62] IsExtensible
same
を返します。
cross
を返します。
method
[63] PreventExtensions
same
を返します。
cross
を返します。
method
[64] GetOwnProperty
params
P
same
  1. [32] desc を、 OrdinaryGetOwnProperty(this, P) に設定します。
  2. [33] thisDefaultProperties の値に P が含まれるなら、
    1. [34] descConfigurableに設定します。
  3. [35] desc を返します。
cross
  1. [37] 特性を、 ! CrossOriginGetOwnPropertyHelper(this, P) に設定します。
  2. [38] 特性未定義でなければ、
    1. [39] 特性を返します。
  3. [40] それ以外なら、
    1. [41] SecurityError 例外投げます。
method
[65] DefineOwnProperty
params
P, Desc
same
  1. [46] thisDefaultPropertiesの値が P を含むなら、
    1. [47] を返します。
  2. [48] それ以外なら、
    1. [49] ? OrdinaryDefineOwnProperty(this, P, Desc) を返します。
cross
を返します。
method
[66] Get
params
P, Receiver
same
? OrdinaryGet(this, P, Receiver) を返します。
cross
? CrossOriginGet(this, P, Receiver) を返します。
method
[67] Set
params
P, V, Receiver
same
? OrdinarySet(this, P, V, Receiver) を返します。
cross
? CrossOriginSet(this, P, V, Receiver) を返します。
method
[68] Delete
params
P
same
? OrdinaryDelete(this, P) を返します。
cross
を返します。
method
[69] OwnPropertyKeys
same
! OrdinaryOwnPropertyKeys(this) を返します。
cross
! CrossOriginOwnPropertyKeys(this) を返します。

歴史

JavaScript 1.0

[28] JavaScript 1.0Location オブジェクトが導入され、URL分解属性が追加されました。

JavaScript 1.1

[29] JavaScript 1.1reloadreplace が追加されました。

[30] location.origin は10年代に追加されました。

メモ

[2] Re: WebIDL and prototype chains (Maciej Stachowiak 著, 版) http://lists.w3.org/Archives/Public/public-webapps/2009JulSep/0269.html

[3] [whatwg] JS "redirects" and session history ( 版) http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2010-July/027372.html

[4] Web Applications 1.0 r7512 Make sure <iframe name=location> doesn't override Document.location ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7511&to=7512

[5] Window Object 1.0 ( ( 版)) http://www.w3.org/TR/Window/#window-location

[6] [whatwg] Location object identity and navigation behavior ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-January/038527.html

[319] [whatwg] Spec for location object needs to make some properties unforgeable; need supporting WebIDL changes ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-November/038015.html

[320] [whatwg] Location object identity and navigation behavior ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-November/038014.html

[321] [whatwg] Proposal: location.parentOrigin ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-November/038019.html

[322] Web Applications 1.0 r7513 Update Location's members to point to the right document. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7512&to=7513

[323] Web Applications 1.0 r7514 Make Location be protected from cross-origin access like Window. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7513&to=7514

[324] Web Applications 1.0 r7515 More security fixes: Location is now entirely Unforgeable, and wording for some other security paragraphs is now consistent. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7514&to=7515

[325] Web Applications 1.0 r7516 Location's security model is actually different than Window's. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7515&to=7516

[326] Window Object 1.0 ( ( 版)) http://www.w3.org/TR/Window/#location

[327] Web Applications 1.0 r7758 Allow custom properties on Location objects to work for the Document whose Location object it originally was. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7757&to=7758

[328] Web Applications 1.0 r7846 Try to match reality better for dynamic location.hash navigation. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7845&to=7846

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

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

[408] IRC logs: freenode / #whatwg / 20140205 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20140205#l-961

[409] Cross-origin windows and how to explain them in ECMAScript semantics ( (David Bruant 著, 版)) http://lists.w3.org/Archives/Public/public-script-coord/2014JanMar/0140.html

[8] Inline URLUtilsReadOnly · whatwg/html@32a7a20 ( 版) https://github.com/whatwg/html/commit/32a7a2092eeff52aca78a0224816a9b327893cc6

[9] Give workers a base URL and clean up shared workers · whatwg/html@b620471 ( 版) https://github.com/whatwg/html/commit/b620471ff823e8e6507b077cf0785a530762f5e3

[15] Tie Location to the Window object · whatwg/html@fdd8216 ( 版) https://github.com/whatwg/html/commit/fdd8216a902a065dd3e205cbbc1b5a6b527970a2

[36] Cross-origin objects: do not wrap JavaScript functions ( (annevk著, )) https://github.com/whatwg/html/commit/db361b608157b5cf9fd0d491d7dc76cdce80380b

[45] Explain why cross-origin properties are configurable (domenic著, ) https://github.com/whatwg/html/commit/7891ea33f643f2b6af18dacc532378671c922b76

[50] document.location requires document to be fully active (annevk著, ) https://github.com/whatwg/html/commit/126ec9eadb149285c8f41a40929ff53ca8112826

[51] Throw for cross-origin [[Delete]] and use "SecurityError" as needed (annevk著, ) https://github.com/whatwg/html/commit/9b22d034cd5a89cac9e54174d009ef8a256bcf13

[52] Make Location's toString() work and drop its toJSON() (annevk著, ) https://github.com/whatwg/html/commit/74a78cb74c07b81bc195bdf50d90811f8f5ee5aa

[53] Remove javascript URL case from <a>/<area>/Location hash setter (annevk著, ) https://github.com/whatwg/html/commit/deea9fba916cb6e66c7dcfc57442cf25ac0441a1

[54] Tweak the exposure of cross-origin properties (domenic著, ) https://github.com/whatwg/html/commit/79b4fbc6cfa2123620fa05c27579f4ec1e7d9c5d

[55] Why are indexed properties on WindowProxy not enumerable in the spec? · Issue #2753 · whatwg/html () https://github.com/whatwg/html/issues/2753

[56] Why are indexed properties on WindowProxy not enumerable in the spec? · Issue #2753 · whatwg/html () https://github.com/whatwg/html/issues/2753

[57] Tweak the exposure of cross-origin properties by domenic · Pull Request #2777 · whatwg/html () https://github.com/whatwg/html/pull/2777

[58] Enumerate fewer cross-origin properties (annevk著, ) https://github.com/whatwg/html/commit/ad8823782e7f6b7d60f8e216901bb76d1a53dd6d

[59] Enumerable cross-origin properties don't seem to be web-compatible · Issue #3183 · whatwg/html () https://github.com/whatwg/html/issues/3183

[70] Enumerate less cross-origin properties by annevk · Pull Request #3186 · whatwg/html () https://github.com/whatwg/html/pull/3186

[71] Make crossOriginObject.then undefined for promises (annevk著, ) https://github.com/whatwg/html/commit/6031e3a2d66ee2ff11d09abd18e6a25a3c78c5ba

[72] No way to resolve a Promise with a cross domain WindowProxy · Issue #536 · whatwg/dom () https://github.com/whatwg/dom/issues/536

[73] Make crossOriginObject.then undefined for promises by annevk · Pull Request #3242 · whatwg/html () https://github.com/whatwg/html/pull/3242

[74] WindowProxy and Location use ordinary internal methods by default (annevk著, ) https://github.com/whatwg/html/commit/44da6795888d90cc7d4181a57e5b7aeafe461fb5

[75] Correct branching logic in choosing a browsing context by annevk · Pull Request #4197 · whatwg/html () https://github.com/whatwg/html/pull/4197

[76] Handle cross-origin "then" and friends at a later point (annevk著, ) https://github.com/whatwg/html/commit/5e370be9b9d48fe5106472db0ea65e01c64387bc

[77] Handling of "then" on cross-origin windows doesn't match what we agreed to do or browsers · Issue #4251 · whatwg/html () https://github.com/whatwg/html/issues/4251

[78] Handle cross-origin "then" and friends at a later point by annevk · Pull Request #4269 · whatwg/html () https://github.com/whatwg/html/pull/4269

[79] WindowProxy and Location use ordinary internal methods by default (annevk著, ) https://github.com/whatwg/html/commit/44da6795888d90cc7d4181a57e5b7aeafe461fb5

[80] Should clearly define that the ordinary object internal methods are used when not stated otherwise for WindowProxy and Location · Issue #4189 · whatwg/html () https://github.com/whatwg/html/issues/4189

[81] Clarify that WindowProxy and Location use ordinary internal methods by default by annevk · Pull Request #4191 · whatwg/html () https://github.com/whatwg/html/pull/4191

[82] Only run "perform a security check" for Window and Location objects (annevk, , ) https://github.com/whatwg/html/commit/e46fc2f59a064ab4e45b9f3e6fa9322ad591ef0f

[83] Only run "perform a security check" for Window and Location objects by annevk · Pull Request #5141 · whatwg/html () https://github.com/whatwg/html/pull/5141

[84] Consolidate performing a security check in the spec with implementations · Issue #2360 · whatwg/html () https://github.com/whatwg/html/issues/2360