Document.activeelement Filter Select File Pop-up causes page loss

Source: Internet
Author: User

The online exam page often needs to detect if the user is cheating.

Generally is the way to monitor the page is out of focus, and there are many ways to lose focus, such as QQ pop-up window, switch page, switch program, input file upload Select file, etc.

Selecting files is normal, in which case you need to filter

This article is very simple, actually is the use of document.activeelement , get the focus element on the current page

You can trigger a mouse click or tab toggle to get

Generally, form input, textarea, select, and so on, is also the body item

        <inputtype= "text"name="">        <inputtype= "File"name="">        <Scripttype= "Text/javascript">Window.onblur= function() {                varElem=document.activeelement;                Console.log (Elem); if(Elem.getattribute ('type') !== 'file') {Console.log ('Blur');        }            }; </Script>

Filter the file selection caused by the pop-up window, the support of this property is still possible

However, the use of JS detection is QQ pop-up window, at present, still does not work, had to prompt users to close the test before the application may be pop windows

Document.activeelement Filter Select File Pop-up causes page loss

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: 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.