How to discourage browser tab-switching during an online test?

I’m making a simple addition/subtraction math-test website on an urgent basis where each question and its answer’s input field is in a repeater and a final submit button ends the test.

I’d like to prevent or at least discourage tab-switching during the test, as well as discourage opening other windows or applications.

One idea to do this was to create an alert (“THE TEST ENDS IF YOU LEAVE THIS PAGE BEFORE SUBMISSION”) the moment the page/document loses focus, while ensuring the user can’t submit if JavaScript is disabled.

Unfortunately, Wix Corvid declared $w.(“#Document”) and $w.(" #Page ") as invalid selectors in both the site and the page code. So I couldn’t rely on OnFocus() or OnBlur() event-listeners to detect tab-switching.

Please help me find an alternative way to detect/discourage tab-switching.

It can’t be done using Corvid.
If you have a premium account maybe you’ll be able to achieve that by putting a code snippet in the tracking & analytics section, but you’ll have to search the web to find the code.

Could someone please help me understand why the $w.(" #Document “) and $w.(” #Page ") selectors don’t work? I know they exist, from the documentation at https://www.wix.com/corvid/reference/$w.Document.html .

Also, thanks for the reply!

Remove the #

Thanks