简体   繁体   中英

Ways to prevent user from reloading/refreshing page in quiz taking application

I am currently trying to figure out a strategy for not allowing a user to refresh/reload a page during the quiz. I know it's not a good idea, or even possible, to completely disable the reload feature in the browser, but are there any other ways to keep the user from being able to restart the exam by reloading the page?

I currently have the browser window not displaying the back button, and typing in the url is not allowed. I know I can disable the context menu from the right-click on the mouse, but keyboard shortcuts for reloading the page are still allowed. Any ideas on how I should approach this?

EDIT

I should change this to mean that I am not actually attempting to disable the browser reload feature, but instead, if the user does attempt to reload, I want to redirect them so that the test ends, or some other event takes place, instead of the test restarting.

Currently, I am using a localStorage variable to indicate if it's a reload and going from there. Is this the best solution?

Thanks!

You are fighting an uphill, unwinnable battle if you are attempting to secure a web application using only client-side technology (javascript). There are always ways to get around the measures you're attempting.

A workable solution would be track the quiz progress server-side after every user decision. This way, if the user tries to reload (or otherwise start over, re-answer, or skip around) you can simply return them to where they belong.

I can think of a solution that detects if the page is refreshed.

If you're using PHP, you can set a SESSION variable on loading and then check to see if that variable is set yet

    <?php
       if(!isset$_SESSION['loaded'])
       {
          $_SESSION['loaded'] = 1;
       }
       else
       {
           echo 'You refreshed, your quiz is over ;-) ';
       }
    ?>

As for disabling refreshing, you'd be bordering on malware to achieve it, ie. filtering all keyboard input for 'F5' key or 'Ctrl + R' from JavaScript, and disregarding keyboard input when they enter those shortcuts. I'm not sure if that's possible/ethical

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