我想要做的是,在页面退出或被导航时,任何时候都会出现弹出框。现在我有
<script type="text/javascript">
function box()
{
var r=confirm("Message");
if (r==true)
{
window.location.href="yes.html";
}
else
{
window.location.href="no.html";
}
}
</script>
<body onunload="box();">我对此有两个问题:
no.html或yes.html。有人能告诉我这怎么可能吗?
发布于 2012-09-24 01:02:12
试试这个:
<script type="text/javascript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
setTimeout(function() {
setTimeout(function() {
window.location.href="yes.html";
}, 1000);
},1);
return "Message";
}
</script>只能捕获停留在页面上的选项,不能覆盖离开页面的用户。类似于:Way to know if user clicked Cancel on a Javascript onbeforeunload Dialog?
https://stackoverflow.com/questions/12557627
复制相似问题