如何使用JavaScript来阻止浏览器后退按钮 [英] how to stop browser back button using javascript
问题描述
我在PHP做网上测验应用程序。我想限制的用户,而在考试回去。
我曾尝试下面的脚本,但是它停止我的定时器。
我该怎么办,请给我建议。
我已经包括源$ C $ C。
计时器被存储在cdtimer.js
I am doing online quiz app in php. I want to restrict user while going back in exam. I have tried following script but it stops my timer. What should I do please suggest me. I have included source code. The timer is stored in cdtimer.js
<script type="text/javascript">
window.history.forward();
function noBack()
{
window.history.forward();
}
</script>
<body onLoad="noBack();" onpageshow="if (event.persisted) noBack();" onUnload="">
我有考试计时器这需要考试持续时间从的 MySQL数据库的,并相应启动定时器停止,当我把code禁用后退按钮。会有什么问题。
I have exam timer which takes duration of exam from mysql db and starts timer accordingly it stops when I put code for disabling back button. what will be the problem.
推荐答案
有为什么禁用后退按钮将无法真正工作的原因很多。最好的办法是警告用户:
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 "You 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
这篇关于如何使用JavaScript来阻止浏览器后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!