0

I have created a self-evaluation exam for the students. I don't want them to go to the previous question even if the hit the browser back button. I read in forums that disabling the browser button is not possible. So, I am thinking to use redirect_to once students hit browser back button.

Is there any way in which this can be achieved?

Thank you

krishna
  • 75
  • 1
  • 2
  • 11
  • Use JS probably? https://stackoverflow.com/questions/25806608/how-to-detect-browser-back-button-event-cross-browser?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Rockwell Rice Apr 18 '18 at 16:43

1 Answers1

0

You can't do that with Rails. The logic should go into the front-end application.

Place the below JS in the head section of the page.

<script type = "text/javascript" >

   function disableBrowserBack(){window.history.forward();}

   setTimeout("disableBrowserBack()", 0);

   window.onunload=function(){null};

</script>
Abhilash Reddy
  • 1,499
  • 1
  • 12
  • 24