Display if the document has focus:
if (document.hasFocus()) {
text = "The document has focus.";
} else {
text = "The document does NOT have focus.";
}
Try it Yourself »
The hasFocus()
method returns a true
if the document (or any element in the document) has focus.
Otherwise it returns false
.
document.hasFocus()
NONE |
Type | Description |
Boolean | true if the document (or an element in the document) has focus.Otherwise false . |
document.hasFocus()
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!