HTML DOMドキュメントhasFocus()
例
ドキュメントにフォーカスがあるかどうかを表示します。
if (document.hasFocus()) {
text = "The document has focus.";
} else {
text = "The document does NOT have focus.";
}
定義と使用法
このhasFocus()
メソッドはtrue
、ドキュメント(またはドキュメント内の任意の要素)にフォーカスがある場合にaを返します。
それ以外の場合はを返しますfalse
。
構文
document.hasFocus()
パラメーター
NONE |
戻り値
タイプ | 説明 |
ブール値 | true ドキュメント(またはドキュメント内の要素)にフォーカスがある場合。それ以外の場合 false 。 |
ブラウザのサポート
document.hasFocus()
すべてのブラウザでサポートされています:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |