刷新页面然后关闭浏览器/选项卡时,BeforeUnload 不显示“离开”对话框
我正在努力在用户关闭浏览器/选项卡时显示消息(离开对话
)。
到目前为止,当我在浏览器中打开 URL 并进行一些编辑,然后关闭浏览器/选项卡时,会显示 Leave Dialogue
。
出现问题,当我刷新
页面然后立即关闭浏览器时,离开对话
不显示。 我已经调试了 BeforeUnload
事件,并且该事件以及 Return
值正在触发,但在这种情况下,“离开对话”仍然没有显示。
这是我的代码:
window.addEventListener("beforeunload", function (e) {
if (!anIsRefresh && IsViewMode() == false) {
anIsRefresh = false;
return e.returnValue = "";
return "";
}
});
我正在开发 Asp.NET MVC。
另一件事:当我重新加载/刷新
,然后不是关闭浏览器/选项卡
,而是单击 DOM 中的任意位置,然后关闭浏览器/选项卡
,离开对话
出现。 出于这个原因,我尝试在触发 BeforeUnload
时强制关注该字段,但仍然不起作用。
I am working to show message (Leave Dialogue
) when User close the Browser/Tab.
Until now, when I open the URL in the Browser and do some editing, and then close the Browser/Tab, the Leave Dialogue
shows up.
The problem occurs, when I Refresh
the page and then immediately close the Browser, the Leave Dialogue
doesn't show up.
I have debugged the BeforeUnload
event, and the event is firing as well as the Return
value, but still, the Leave Dialogue doesn't show in this scenario.
Here is my code:
window.addEventListener("beforeunload", function (e) {
if (!anIsRefresh && IsViewMode() == false) {
anIsRefresh = false;
return e.returnValue = "";
return "";
}
});
I am working on Asp.NET MVC.
Another thing: When I Reload/Refresh
and then instead of closing Browser/Tab
, click anywhere in DOM and then afterward close the Browser/Tab
, the Leave Dialogue
shows up.
For this reason, I have tried to forcefully focus on the field whenever BeforeUnload
is triggered but still, it doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论