Document.location
Document.location
は読み取り専用のプロパティで、この文書の URL に関する情報を持った Location
オブジェクトを返します。これはその URL を変更したり他の URL を読み込んだりするためのメソッドも提供しています。
Document.location
は読み取り専用の Location
オブジェクトですが、 DOMString
を代入することができます。つまり、 document.location が文字列であるかのように扱うことができます。 document.location = 'http://www.example.com'
は document.location.href = 'http://www.example.com'
の別名です。
URL を文字列として受け取るだけであれば、読み取り専用の document.URL
プロパティも利用することができます。
現在の文書が閲覧コンテキスト内にない場合、返値は null
となります。
構文
s
locationObj = document.location document.location = 'http://www.mozilla.org' // Equivalent to document.location.href = 'http://www.mozilla.org'
例
console.log(document.location);
// Location オブジェクトをコンソールへ表示
仕様書
Specification |
---|
HTML Standard # the-location-interface |
ブラウザーの互換性
BCD tables only load in the browser
関連情報
- 返値のインターフェイスである
Location
- 同様の情報で閲覧コンテキストに結びつけられている
Window.location