Solved

window.onClose in IE

Posted on 2004-03-22
16
135,564 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now