在许多网站上看到这样的一个效果:
就是在用户离开或者关闭当前页面时,会弹出一个确认对话框,
当用户确认离开时,点击确定则关闭当前页面,
如果说用户是误操作,不愿离开当前页面,点击取消
则继续留在当前页面。
请问这样的效果如何实现?
说一说原理也行!谢谢了!!!
就是在用户离开或者关闭当前页面时,会弹出一个确认对话框,
当用户确认离开时,点击确定则关闭当前页面,
如果说用户是误操作,不愿离开当前页面,点击取消
则继续留在当前页面。
请问这样的效果如何实现?
说一说原理也行!谢谢了!!!
window.onbeforeunload = function (){
return "xxxx";
}
var g_blnCheckUnload = true;
function RunOnBeforeUnload()
{
if(g_blnCheckUnload)
{
window.event.returnValue = '确认关闭窗口吗?';
}
}
function bypassCheck()
{
g_blnCheckUnload = false;
}
onbeforeunload=RunOnBeforeUnload;
</script>
</head>
<body onbeforeunload="RunOnBeforeUnload()">
var g_blnCheckUnload = true;
function RunOnBeforeUnload()
{
if(g_blnCheckUnload)
{
window.event.returnValue = '确认关闭窗口吗?';
}
}
function bypassCheck()
{
g_blnCheckUnload = false;
}
onbeforeunload=RunOnBeforeUnload;
</script>
</head>
<body onbeforeunload="RunOnBeforeUnload()">
<script>
function aaa(e){
e=e||window.event
e.returnValue="真的要离开本页面吗?"
}
</script>
<body onbeforeunload="aaa(event)">
<head>
<script>
function window.onbeforeunload() {
if (event.clientX>document.body.clientWidth && event.clientY<0 ||event.altKey)
window.event.returnValue="";
}
</script>
<head>
<body>
<a href="#" onClick="window.close();">注销</a>
</body>
</html>