目录

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 »

Description

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 Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes