如果事件 onbeforeunload
触发,我如何查明用户是否在显示的框中按下了左按钮(确认)或右按钮(取消)?
function ask()
{
var ret = confirm("sure?"); //ERROR: Blocked confirm('sure?') during beforeunload.
if (ret) console.log("User pressed confirm button");
return "are you sure?";
}
<body onbeforeunload="return ask()">
<h1>onbeforeunload Test</h1>
<a href="http://www.google.de">Google</a>
</body>
最佳答案
为了安全起见,这不再可能了。因此,除了返回一些文本之外,您不能做任何其他事情,如果用户拒绝刷新,页面将不会刷新,在其他情况下页面将被刷新。
关于javascript - 检查用户在 onbeforeunload 的提示下单击了哪个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36543636/