HTML DOM Document hasFocus()
Example
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 »
Definition and Usage
The hasFocus()
method returns a true
if the document (or any element in the document) has focus.
Otherwise it returns false
.
Syntax
document.hasFocus()
Parameters
NONE |
Return Value
Type | Description |
Boolean | true if the document (or an element in the document) has focus.Otherwise false . |
Browser Support
document.hasFocus()
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |