Document.location - ロケーション
locationは、Documentのプロパティです。ドキュメントのロケーション(Location)を返します。Window.locationと同じです。
概要
- 名前
- location
- 所属
- Document
- IDL
[PutForwards=href, Unforgeable] readonly attribute Location? location;
- 仕様書
- https://html.spec.whatwg.org/multipage/history.html#dom-document-location
説明
ロケーション(Location)を返す。読み取り専用なので、値を代入して変更することはできない。
デモ
Document.locationのデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<body>
<script>
var value = document.location ;
console.log( value ) ;
document.body.appendChild( new Text( value ) ) ;
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● | ● | ● | ● | ● | ● | ● | ● |
関連記事
- グローバルオブジェクト
- JavaScriptの各グローバルオブジェクト(組み込みオブジェクト)の使い方を、初心者向けにデモとサンプルコード付きでまとめています。各ブラウザのサポート状況など。
- Document
- Documentは、ドキュメントを管理するための機能を備えたインターフェイスです。
- Document.getElementsByClassName()
- getElementsByClassName()は、Documentのメソッドです。class属性を指定して要素を取得します。
- 別ページに移動させる
- リンクをクリックしなくても、ユーザーを指定したページに移動させます。