• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1116
  • Last Modified:

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?"
  • 2
2 Solutions
Michel PlungjanIT ExpertCommented:
Nope. onClose does not exist.

You are looking for
<body onBeforeUnload="returnValue='Please don\'t go'">

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';
window.onbeforeunload = ConfirmClose;

Open in new window

Michel PlungjanIT ExpertCommented:
That will indeed work on some versions and for an unknown period...
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.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now