Solved

Internet Explorer closing event -catching  in JavaScript

Posted on 2007-11-21
4
1,103 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now