How can I stop the browser back button using JavaScript?

前端 未结 30 3256
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 00:07

I am doing an online quiz application in PHP. I want to restrict the user from going back in an exam.

I have tried the following script, but it stops my timer.

30条回答
  •  孤街浪徒
    2020-11-22 00:56

    Just set location.hash="Something". On pressing the back button, the hash will get removed from the URL, but the page won't go back.

    This method is good for preventing going back accidentally, but for security purposes you should design your backend for preventing reanswering.

提交回复
热议问题