Solved

window.onClose in IE

Posted on 2004-03-22
16
135,609 Views
Last Modified: 2011-08-18
Hi Experts.

Can any of you tell me how do I manage the window.onClose event in Internet Explorer, What I really need is to control when the user closes the window, but without using events like <BODY onUnload> or <BODY onBeforeUnload>.

Thanks in advance

Javier
0
Comment
Question by:jarasa
  • 6
  • 3
  • 2
  • +5
16 Comments
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 10650923
window.onunload = function() {

 // code

}
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10650926
same as:

window.onunload = function(){alert('closing')};

Or:
window.onbeforeunload = function(){alert('closing')};


But you cannot check wether the page is moving, reloading or browser closing.
It is out of control of scripting.


0
 
LVL 63

Accepted Solution

by:
Zvonko earned 250 total points
ID: 10650960
Here an example:
http://experts-exchange.com/Web/Web_Languages/JavaScript/Q_20926025.html

<script>
window.onunload = function(){if(self.screenTop>9000)alert('Closed.')}
</script>

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
LVL 6

Author Comment

by:jarasa
ID: 10650973
>but without using events like <BODY onUnload> or <BODY onBeforeUnload>.

That's why I put that exception zvonko.

Is not any other way to do it? I'm using a FRAMESET with 5 documents and if I use that it repeats the message 5 times.

Javier
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10651056

you can use window.closed value somewhere you want..

if (window.closed==false)
{
      alert("hai")
}
0
 
LVL 25

Assisted Solution

by:devic
devic earned 250 total points
ID: 10651160
here is my patent :)

=================
<script>
var UserClicked=false;
document.onkeydown=spyclick;
document.onmousedown=spyclick;
function spyclick()
{
      UserClicked=true;
      setTimeout("UserClicked=false",2000);
}
function popup()
{
      if(!UserClicked)
      {
            var win=window.open("","","width=300,height=300")
            win.document.write("kuku, come back! ;)")
      }
}
window.onbeforeunload=popup;
</script>

0
 
LVL 7

Expert Comment

by:searlas
ID: 10651178

Put your onunload handler in the frameset document instead of in the frames html.
Then you'll only get it called once no matter how many frames you have...
0
 
LVL 3

Expert Comment

by:xp_commander
ID: 10651427
Check here for the Accepted code :- http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20924470.html

You could save points if you do a search before posting similiar questions.

0
 
LVL 6

Author Comment

by:jarasa
ID: 10656719
Thank all for the Help.

I finally solved this way:
I put a var closed on the top.frames['Header'] HTML document and check whether is already closed or not so it only fires the closeSession fucntion once.

<Script>
window.onbeforeunload = function(){if((window.event.clientX<0)||(window.event.clientY<0))closeSession()}
function closeSession() {
if (top.frames['Header']!=null) {
if (top.frames['Header'].closed==0) {
top.frames['Header'].cerrarTodas1();
openCerrar("'../../FwkServlet?view=vega&ucase=ForwardUC&url=/jsp/login/session_invalidate.jsp", 400, 250, null, null,'');
top.close();
top.frames['Header'].closed= top.frames['Header'].closed+ 1;
} else {
openCerrar("'../../FwkServlet?view=vega&ucase=ForwardUC&url=/jsp/login/session_invalidate.jsp", 400, 250, null, null,'');
top.close();
}
}            
}
</Script>

Javier


xp_commander: I did a search before but I was looking for something more specific

>You could save points if you do a search before posting similiar questions.

As an expert I have unlimited points to ask so I'm not worrie about saving some, thanks anyway for you comment


0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10657082
Thanks for points and thank you for feedback.
0
 
LVL 6

Author Comment

by:jarasa
ID: 10657645
Ain't we here for that??

:c)

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10657700
Yeap! :-)
0
 
LVL 1

Expert Comment

by:ghostReckon
ID: 12224933
Hi
Is it possible to stop clients (users) by clicking X (on browser upper right conner) to exit a application. I have read the above and feel the onClose method of JavaScript might help.
Pls help

Thanks
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12224985
Hello ghostReckon,
be welcome to Expert Exchange.

You are new here, so you perhaps do not know that opening new Questions should be the method to start a discussion.
By the way, there is NO way to stop user closing his browser windows.

See you around,
Zvonko
0
 
LVL 1

Expert Comment

by:ghostReckon
ID: 12225040
Thanks Zvonko
I had found that out and submitted the question i guess the way it should be.
Thanks for you help anyways.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12225075
You are welcome.
0

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Grunt script for Build Process 1 44
tiny glitch in my main slider 3 40
Insert Button on a table 16 38
html border input line 7 16
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

821 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