Preventing users from going backwards


We created a quiz on driverstest.info that allows people to get coins if they get the right answer. If you get enough coins you can get on the high score list. However, I found that some people were using the back button on the browser and doing the same question again and again. The better idea would be to track if the user had done that question before and penalize or prevent them from  getting coins for doing the same question, and I will try to do that for the long term. I did learn a little trick though to prevent people from using the back button. By adding this javascript in the head (I didn’t test if this would work at the bottom)


  <script type="text/javascript"> 
window.history.forward();
    function noBack() { window.history.forward(); }
</script>  

and add the following to the body tag…

<body onload="noBack();"
    onpageshow="if (event.persisted) noBack();" onunload=""> 

this would prevent people from easily going back to the question they just finished. There are ways to get around this for the user, but they would have to have a lot more free time than me to waste to do it.


Leave a Reply

Your email address will not be published. Required fields are marked *