gpt4 book ai didi

javascript - 刷新 URL 时出现两次 onbeforeunload 确认提示?

转载 作者:行者123 更新时间:2023-11-30 05:51:22 25 4
gpt4 key购买 nike

我正在使用 window.onbeforeunload 进行用户确认,当用户离开页面时,但确认警报仅在 IE 中出现两次。

我的代码是:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>User confirmation</title>

<script type="text/javascript">
/* Used for confirmation , to closing the window */
window.onbeforeunload = function() {

return "Are you sure want to LOGOUT the session ?";
};
</script>
</head>
<body>
<p>Folow the steps which I said in Stack overflow</p>
</body>
</html>

场景是,

第 1 步:运行我的代码并在 IE 中打开它。

第 2 步:应用程序加载后,关闭浏览器窗口。您将收到一条确认提醒。

第 3 步:在确认提示中给出取消

第 4 步:然后按地址栏中的 ENTER 按钮 刷新 URL。

第 5 步:在警报中给出 ok

第 6 步:现在您将再次收到确认提示。

谁能告诉我如何解决这个问题?

最佳答案

这是 IE 的设计。

阅读列出引发该事件的所有事物的备注。

http://msdn.microsoft.com/en-us/library/ie/ms536907%28v=vs.85%29.aspx

您可以使用计时器来避免这种情况:

window.onbeforeunload may fire multiple times

关于javascript - 刷新 URL 时出现两次 onbeforeunload 确认提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14649764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com