window.onClose in IE

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
LVL 6
jarasaAsked:
Who is Participating?
 
ZvonkoConnect With a Mentor Systems architectCommented:
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
 
Saqib KhanSenior DeveloperCommented:
window.onunload = function() {

 // code

}
0
 
ZvonkoSystems architectCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
jarasaAuthor Commented:
>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
 
venkateshwarrCommented:

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

if (window.closed==false)
{
      alert("hai")
}
0
 
devicConnect With a Mentor Commented:
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
 
searlasCommented:

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
 
xp_commanderCommented:
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
 
jarasaAuthor Commented:
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
 
ZvonkoSystems architectCommented:
Thanks for points and thank you for feedback.
0
 
jarasaAuthor Commented:
Ain't we here for that??

:c)

0
 
ZvonkoSystems architectCommented:
Yeap! :-)
0
 
ghostReckonCommented:
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
 
ZvonkoSystems architectCommented:
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
 
ghostReckonCommented:
Thanks Zvonko
I had found that out and submitted the question i guess the way it should be.
Thanks for you help anyways.
0
 
ZvonkoSystems architectCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.