Returns true if the web page is in focus, otherwise returns fasle
What is focus? Focus refers to whether the user is active on the page. Specifically, whether the mouse is active within the web page. Or whether the content in the web page is selected, or the cursor exists in an element of the page. If one of the conditions is met, the page is in focus. Note that the hasFocus method only targets web pages and not browsers. In the following example. When you click on a web page with your mouse. The web page is in focus. After you click the address bar of the browser with the mouse. The web page loses focus and displays false. Remember again that the hasFocus method can only run on document objects. Please see the example below