1

I am developing application, where user has to write certification exam online. Once user clicks start exam button, I am opening popup window to give exam. But we should not allow user to move away from this window(To prevent him from copying answer by googling in another window). User should not be able to move away from active window in any way like pressing ALT+TAB (or) WINDOWS+D.

Basically, in javascript, we need to prevent user to move away from current window in all possible ways. How to do it?

Vikram Babu Nagineni
  • 3,411
  • 6
  • 25
  • 34
  • 4
    Oh you want us to write a virus... – Jonas Wilms Sep 15 '16 at 13:16
  • No. This is a requirement. We want user to write exam without googling and copy answer. – Vikram Babu Nagineni Sep 15 '16 at 13:18
  • 1
    But because any virus might also want to do that, *any* reasonable browser won't let a script do that. You should search for native applications and restricted window managers / kiosk modes (probably there are solutions for Windows and Linux). – Martin Nyolt Sep 15 '16 at 13:19
  • 1
    As @Martin said you would be better of looking at other avenues as I don't believe this is possible, you would be better off detecting if the focus has moved away from the test window and handling that scenario how you would like. – Corporalis Sep 15 '16 at 13:23
  • 2
    Javascript does not have this amount of control over the desktop, you would be better of creating a program that displays the website in it. – x13 Sep 15 '16 at 13:25

1 Answers1

1

Preventing users from leaving your site, is all a spamer needs. Thats why it is impossible. The only thing you can do, is to check if the user moved away. This will stop the js execution: (See Detect if browser tab is active or user has switched away for original code)

 var vis = (function(){ var stateKey, eventKey, keys = { hidden: "visibilitychange", webkitHidden: "webkitvisibilitychange", mozHidden: "mozvisibilitychange", msHidden: "msvisibilitychange" }; for (stateKey in keys) { if (stateKey in document) { eventKey = keys[stateKey]; break; } } return function(c) { if (c) document.addEventListener(eventKey, c); return !document[stateKey]; } })();

vis(function(){
if(vis()==false){
alert("You left the site. You try to cheat");
//do sth else
}
});
Community
  • 1
  • 1
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151