简体   繁体   中英

how can i stop opening other browsers or tabs using javascript or jquery when a user is taking a quiz?

i have a quiz module in my rails app. here i can create a quiz and i can assign it to the users. once the quiz is assigned to the users they will get an email which contains the link to open that quiz. up to here is fine. now i want to implement a functionality by using which i want to stop the user from opening other browsers or the tabs of the current browser on which the user is taking the test currently. so by using this functionality i want to restrict the user from searching the answers in the internet as long as he was on the test. but don't know how to implement it with javascript or jquery.

It's impossible for a web page to prevent users from opening new windows/tabs in their browser. You can however check to see if the user navigates away from your page using the blur event listener on the window object.

window.addEventListener("blur", function () {
    // window has lost focus
});

Though you can never be sure what the user has done - they may have switched applications or a popup may have stolen focus from the window.

You can't. Even if you could, there's nothing to stop the person taking the quiz from using their phone, tablet, the computer in the next room, etc.

The only way to ensure that no outside resources are used is to control the setting in which the quiz is being taken and watch the person who is taking the quiz. You might be able to do that with video, but it would be resource-intensive (eg, you and/or your staff have to watch each and every quiz taker).

You are probably looking for tracking whether the test page is in focus or not. This can be done using focus and blur events of the window. You could then invalidate the session and alert the user that they need to start giving the test again. Please check the below link for more information.

How to tell if browser/tab is active

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM