HasFocus is a unique method of document. It is used to determine whether the current webpage gets the focus. If the webpage is in the focus state, true is returned; otherwise, fasle is returned.
What is the focus? The focus is whether the user is active on this page. whether the mouse is active on the webpage. or whether the content on the webpage has been selected, or the cursor exists in an element on the page. if one of the conditions is met, the page is in the focus state. note that the hasFocus method is applicable only to webpages and not browsers. in the following instance. when you click a webpage. the webpage is in focus state. click the address bar of your browser. the webpage loses its focus and displays false. again, the hasFocus method can only run in the document Object. see the following example.
The Code is as follows:
Dom: hasFocus Method Instance
Click the webpage area. This indicates that the webpage gets the focus and is displayed as true. Click the address bar of the browser. If the webpage loses the focus, the page is displayed as false.
Foot home