Example of using javascript hasFocus

Source: Internet
Author: User

Returns true if the webpage is in focus state; otherwise, returns fasle.
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.
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> Dom: hasFocus Method Instance </title>
</Head>
<Body onfocus = "getFocus ()" onblur = "Empty_Focus ()">
<H2> click the webpage area. This indicates that the webpage has a focus and is displayed as true. Click the address bar of the browser. If the webpage loses its focus, the page is displayed as false. <Hr/>
<A href = "http://www.jb51.net" onfocus = "getFocus ()"> Home of foot </a>
<Span id = "c"> </span>
<Script language = "javascript">
Function getFocus (){
Document. getElementById ("c"). innerHTML = document. hasFocus ();
}
Function Empty_Focus (){
Document. getElementById ("c"). innerHTML = document. hasFocus ();
}
</Script>
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.