Solved

Internet Explorer closing event -catching  in JavaScript

Posted on 2007-11-21
4
1,105 Views
Last Modified: 2008-02-01
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?"
0
Comment
Question by:Silas2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:imitchie
ID: 20326934
window.onclose?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20327095
Nope. onClose does not exist.


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

Assisted Solution

by:rallsaldo
rallsaldo earned 60 total points
ID: 20328323
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 65 total points
ID: 20328476
That will indeed work on some versions and for an unknown period...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question