By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

closing a child window when parent window is closed is not working in mozilla

P: 5
From a parent window a new child window is open with window.open

[HTML]<script type="text/javascript" language="JavaScript" >

function abc()
{

if(window.event.clientY <0 && window.event.clientY <-80 )
{
if (win2 && !win2.closed) // win 2 is the child window
{
alert("Do you want to close all windows");
win2.close();
}

}
else if (win2 && !win2.closed)
{
win2.close();
}

}
</script>


<body bgcolor="#F7F7ef" onUnload="abc()">
[/HTML]

This works with IE , Opera .. this code doesnt work with Mozilla Netscape. What i require when closing the parent page by clciking the X button it should give an alert that ur closing the pages . when logout is pressed , it should give an alert it should just close the child window .Could anyone give me a solution for this
Nov 26 '07 #1
Share this Question
Share on Google+
4 Replies


acoder
Expert Mod 15k+
P: 16,027
You can't check for browser close.

If you want to close child windows, close them onunload.
Nov 27 '07 #2

P: 5
You can't check for browser close.

If you want to close child windows, close them onunload.
Thank You acoder

What i need is when we click on close button on the parent window it should give an alert and close child window whereas while logging out and session timeout it shouldnt give an alert and should close the child window

for that in the function a condition is being checked

Expand|Select|Wrap|Line Numbers
  1. function a
  2. {
  3. if(window.event.clientX<0 && window.event.clientY<-80)
  4. {   
  5.    if (win2 && !win2.closed) 
  6.       {
  7.            alert("closing all windows");
  8.             win2.close();
  9.      }
  10.  }
  11. else
  12. {
  13.     if (win2 && !win2.closed) 
  14.       {
  15.            win2.close();
  16.      }
  17. }
  18.  
  19. }
  20.  
window.event.clientX &Ynear close button is -ve no's
other than that for session and logout it will not give an alert
this function is called on onunload event of the parent window

Like this for mozilla it is window.screenX and window.screenY
i tried using that it gives only one value anywhere i click on the browser (-4,-4)

if anyone could tell why that is it would be very helpful...
Nov 28 '07 #3

P: 5
You can't check for browser close.

If you want to close child windows, close them onunload.
Thank You acoder

What i need is when we click on close button on the parent window it should give an alert and close child window whereas while logging out and session timeout it shouldnt give an alert and should close the child window

for that in the function a condition is being checked

Expand|Select|Wrap|Line Numbers
  1. function a
  2. {
  3. if(window.event.clientX<0 && window.event.clientY<-80)
  4. {   
  5.    if (win2 && !win2.closed) 
  6.       {
  7.            alert("closing all windows");
  8.             win2.close();
  9.      }
  10.  }
  11. else
  12. {
  13.     if (win2 && !win2.closed) 
  14.       {
  15.            win2.close();
  16.      }
  17. }
  18.  
  19. }
  20.  
window.event.clientX &Ynear close button is -ve no's
other than that for session and logout it will not give an alert
this function is called on onunload event of the parent window

Like this for mozilla it is window.screenX and window.screenY
i tried using that it gives only one value anywhere i click on the browser (-4,-4)

if anyone could tell why that is it would be very helpful...
Nov 28 '07 #4

acoder
Expert Mod 15k+
P: 16,027
Please use code tags when posting code. Thanks!
window.event.clientX &Ynear close button is -ve no's
other than that for session and logout it will not give an alert
this function is called on onunload event of the parent window

Like this for mozilla it is window.screenX and window.screenY
i tried using that it gives only one value anywhere i click on the browser (-4,-4)

if anyone could tell why that is it would be very helpful...
Mozilla/Firefox doesn't set the values to -80 (or some other number) when the window is closed. Just close the child windows onunload (which fires when you press refresh or back/forward too). Do you need the child windows away from the current page?
Nov 28 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.