Internet Explorer closing event -catching in JavaScript

Is there a way of catching a form_unload a type of event for Internet Explorer, with a cancel= true type of parameter?
I mean when  a form/IE is exiting without saving, it gives you a chance to ask the user to confirm " Exit without saving?"
Silas2Asked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
That will indeed work on some versions and for an unknown period...
0
 
imitchieCommented:
window.onclose?
0
 
Michel PlungjanIT ExpertCommented:
Nope. onClose does not exist.


You are looking for
<body onBeforeUnload="returnValue='Please don\'t go'">
0
 
rallsaldoConnect With a Mentor Commented:
Hi,

I think the onBeforeUnload event will also fire if the user navigates away from the page, i.e. clicks a link. I have used the following to get round this in javascript (cut down version of actual):


var windowclose = false;
 
function ConfirmClose()
{
     
  if (event.clientY < 0)
   { 
     //I make an AJAX call to another page in here
     event.returnValue = 'Your message';
     
     windowclose=true;
   }
}
 
window.onbeforeunload = ConfirmClose;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.