How can I stop the browser back button using JavaScript?

前端 未结 30 3302
没有蜡笔的小新
没有蜡笔的小新 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 01:09

    There are numerous reasons why disabling the back button will not really work. Your best bet is to warn the user:

    window.onbeforeunload = function() { return "Your work will be lost."; };
    

    This page does list a number of ways you could try to disable the back button, but none are guaranteed:

    http://www.irt.org/script/311.htm

提交回复
热议问题