Document.visibilityState - 表示状態
visibilityStateは、Documentのプロパティです。最上位のブラウジングコンテキストが持つドキュメントの表示状態を文字列で返します。
概要
- 名前
- visibilityState
- 所属
- Document
- IDL
readonly attribute VisibilityState visibilityState; enum VisibilityState { "hidden", "visible", "prerender", "unloaded" };
- 仕様書
- https://www.w3.org/TR/page-visibility/#dom-document-visibilitystate
説明
最上位のブラウジングコンテキストが持つドキュメントの表示状態を表す文字列を、下記のリストの中から返す。
- "hidden"
- ウィンドウが最小化されている、別のタブが表示されて隠れている、OSのロックがかかっている、履歴エントリーが走査されるなどして、ドキュメントが非表示になっている。
- "visible"
- ドキュメントが表示されている。
- "prerender"
- ドキュメントの表示処理が開始され、まだ表示されていない。
- "unloaded"
- ページを離れてドキュメントがアンロードされた。
デモ
Document.visibilityStateのデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<body>
<script>
var value = document.visibilityState ;
console.log( value ) ;
document.body.appendChild( document.createTextNode( value ) ) ;
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● 33+ | ● 18+ | ● 7.1+ | ● | ● 10+ | ● 20+ | ● 7.0+ | ▲ 4.4+ |
関連記事
- Document.URL
- URLは、Documentのプロパティです。ドキュメントに関連付けられたURLアドレスを返します。Location.hrefと値は同じです。
- Document()
- Document()は、Documentのコンストラクタです。新しいオブジェクトを作成します。
- Document.body
- bodyは、Documentのプロパティです。ドキュメントのbody要素を返します。
- HTMLCollection
- HTMLCollectionは、HTML要素の集合を表すオブジェクトです。Elementだけが含まれた配列であるかのように、手軽にインデックス番号でアクセスできます。