Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 14th, 2006, 05:49 AM
Authorized User
 
Join Date: Oct 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with closing the child window

The onUnload event is not triggered when the child window is closed using the 'X' button on the right hand top corner of the window. The onUnload works fine when the window is closed with the help of any link inside the window.

How do we overcome this problem.


 
Old November 14th, 2006, 08:26 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Swarnap!!
Hope this link will help you
http://p2p.wrox.com/topic.asp?TOPIC_ID=26246
Actually you need to trace whether user is clicked on the close button, or alt+F4,


Cheers :)

vinod
 
Old November 14th, 2006, 06:33 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;;The onUnload event is not triggered when the child window is closed using the 'X' button on the right hand top corner of the window.

It should, and does for me regardless if I use Alt+F4 or the red cross, using:
<script>
  function testFunction()
  {
     alert("some text");
  }
</script>

<body onunload="testFunction();">

does the code above work for you? If not, what browser etc are you using?

Wind is your friend
Matt
 
Old November 16th, 2006, 12:38 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Matt!!
Hope this will help you :)
<script>
  function testFunction()
  {
     alert("some text");
  }



function closeWindow()
{

window.parent=self
 //capturing ALT + F4
 if (event.altKey==true && event.keyCode==0 )
{

 testFunction();
   window.close();
  }

Xwidth=window.document.body.offsetWidth-window.event.clientX
YHeight=window.event.clientY
if(Xwidth<=30&&YHeight<0)
{

  testFunction();
  window.close();

}

}
window.onbeforeunload=closeWindow
</script>

<body onunload="testFunction();">


Cheers :)

vinod
 
Old November 16th, 2006, 12:54 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

hi there

I was suggesting the function I posted works onload regardless of which option is used to close a window

Good day to you...

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Close Child window automatically on closing parent vikas67k C# 1 August 26th, 2008 02:00 AM
Closing all child window when browser is closed h@ckerz ASP.NET 2.0 Professional 1 July 17th, 2008 01:04 AM
Closing parent window from child window arnabghosh Javascript How-To 1 December 26th, 2007 01:18 AM
Problem in closing the parent window from a popup rakesh.kashnia1 Javascript 4 July 9th, 2007 05:39 AM
Closing Child Window nickiii General .NET 2 March 31st, 2005 12:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.