Reputation: 8387
I am using the window.onbeforeunload
for user confirmation, when user leaving the page, but confirmation alert happens twice only in IE.
My code is:
<%@ 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>
The scenario is ,
Step 1 : Run my code and open it in IE .
step 2 : After the application loads,close the browser window . You will get a confirmation alert.
step 3 : Give the cancel in the confirmation alert.
step 4 : Then refresh the URL by pressing the ENTER button in the address bar.
step 5 : Give ok in the alert.
step 6 : Now you will the confirmation alert once again.
Can anyone tell me how to solve this problem?
Upvotes: 2
Views: 4170
Reputation: 18968
This is by design in IE.
Read the remarks where all the things that raise that event are listed.
http://msdn.microsoft.com/en-us/library/ie/ms536907%28v=vs.85%29.aspx
you can use a timer to avoid this:
window.onbeforeunload may fire multiple times
Upvotes: 1