?
Solved

window.onClose in IE

Posted on 2004-03-22
16
Medium Priority
?
135,751 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…

650 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