【发布时间】:2019-03-12 23:22:59
【问题描述】:
我正在处理网页,需要在关闭窗口之前向服务器发送disconnect 请求,因此我使用onbeforeunload 事件来执行此操作。
但是,无论我如何尝试,我似乎都无法避免使用onbeforeunload 时出现的默认“保存更改”对话框。
我错过了什么吗?为什么对话框仍然出现?
async function close(event){
// Prevent default warning
event.preventDefault();
event.returnValue = null;
// Here goes my stuff. There's an await here.
// More preventing
return null;
}
// The event is set later
window.onbeforeunload = close;
谢谢。
【问题讨论】:
-
beforeunload 的文档警告说,并非所有浏览器都以相同的方式实现它。您使用的是哪个浏览器?您是否尝试过使用多个浏览器?
-
@focorner 我正在使用最新版本的 Chromium。当然,我希望 Chrome 能够正常工作,因为它是最常用的浏览器。
标签: javascript html onbeforeunload