title: How can I stop the browser back button using JavaScript?
body: <p>I am doing an online quiz application in PHP. I want to restrict the user from going back in an exam.</p>
  <p>I have tried the following script, but it stops my timer.</p>
  <p>What should I do?</p>
  <p>The timer is stored in file <em>cdtimer.js</em>.</p>
  <pre class="lang-html prettyprint-override"><code>&lt;script type=&quot;text/javascript&quot;&gt;
      window.history.forward();
      function noBack()
      {
          window.history.forward();
      }
  &lt;/script&gt;
  
  &lt;body onLoad=&quot;noBack();&quot; onpageshow=&quot;if (event.persisted) noBack();&quot; onUnload=&quot;&quot;&gt;
  </code></pre>
  <p>I have the exam timer which takes a duration for the exam from a MySQL value. The timer starts accordingly, but it stops when I put the code in for disabling the back button. What is my problem?</p>