Solved

window.onClose in IE

Posted on 2004-03-22
16
135,578 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:adilkhan
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why does my button disappear? 3 28
jquery conditionally populate list boxes 2 24
Objects on Same Line 2 18
Google Sheets script efficiency 2 2
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now