允许重新加载,但不允许使用javascript/jquery关闭页面
我想在用户尝试关闭网页时向用户发出警告消息.以下代码可以正常工作,但是我想每60秒刷新一次页面,并且此代码不允许自动刷新.它发出警告刷新消息.但是我只想在用户单击关闭选项卡
i want to give warning message to users when they try to close the webpage.the below code is working just fine but i want to refresh the page after every 60 seconds and this code is not allowing to refresh automatically.it gives warning message for refresh as well. but i want to show warning message only for closing when users click on close tab
<html>
<head><meta http-equiv="refresh" content="60;url=test.html"/>
<script type="text/javascript">
var hook = true;
window.onbeforeunload = function() {
if (hook) {
return "msg here"
}
}
function unhook() {
hook=false;
}
</script>
</head>
<body>
</body>
</html>
您的摘机方法没有在任何地方被调用.为此,您可以使用
Your unhook method is not getting called anywhere. To do so you can refresh the page using
您也可以在其中调用摘机的Javascript,如下图所示.
Javascript where you can call unhook also as shown velow.
<html>
<head>
<script type="text/javascript">
var hook = true;
window.onbeforeunload = function() {
if (hook) {
return "msg here"
}
}
function unhook() {
hook=false;
}
setInterval(function(){
unhook();
window.location.reload()
}, 60000);
</script>
</head>
<body>
</body>
</html>
在60000毫秒(即1分钟)后调用设置间隔的脚本,这使您可以先设置hook = false然后刷新.
The script in set interval is called after 60000 milli-seconds (i.e. 1 min) which allows you to first set hook=false and then refresh.