How to prevent the user from leaving my page [duplicate]

Clash Royale CLAN TAG#URR8PPPHow to prevent the user from leaving my page [duplicate]
This question already has an answer here:
I'm trying to make an online test using spring-mvc and html, css, jquery and I want to prevent the user that is doing the test from leave the test screen while doing the test. Does anybody know how I can do that?
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
disable the user to leave my screen please elaborate it. Do you mean by closing browser window OR just switch the window OR minimize the window?
– VicJordan
9 mins ago
google.com/search?q=prevent+leaving+site
– mplungjan
8 mins ago
Write your test in an .exe instead of a browser if you want to know what they're up-to. Won't stop them using 2nd PC/mobile phone to get your answers though...
– freedomn-m
8 mins ago
If this was possible, do you not think spammers/hackers/advertisers would have already done this to your browser and you wouldn't even be able to have posted this question.
– freedomn-m
6 mins ago
since it's from a web browser, no you cant. the user can make new tabs. close the browser and do many other things.
– IbraHim M. Nada
10 mins ago