Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old June 10th, 2005, 02:00 PM
Authorized User
 
Join Date: Jun 2003
Location: Jewett City, CT, USA.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Determining how a window is closed

I have a Flash application which I'm displaying in a popup. This application has its own close button to be used so that I can save some data to a database and I want to make sure that the users only use this button to close the app. I now have an onBeforeUnload action in the application window, but if the user uses the correct Flash close button, I still get the message. Is there a way to only display the message if the Windows X button or Alt-F4 is used to close the window?

Chris

  #2 (permalink)  
Old June 15th, 2005, 08:39 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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

Hi Chris
Try this

<script>

function closeWindow()
{
 //capturing ALT + F4
 if (event.altKey==true && event.keyCode==0 )
{
  alert("closed1")
   window.close();
  }

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

}

}
window.onbeforeunload=closeWindow
//or we can use it on body tag with (unload) method

</script>

Hope this will help you


Cheers :)

vinod
  #3 (permalink)  
Old June 16th, 2005, 07:53 AM
Authorized User
 
Join Date: Jun 2003
Location: Jewett City, CT, USA.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That works perfectly. Thank you so much for the help!!!

Chris


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing all child window when browser is closed h@ckerz ASP.NET 2.0 Professional 1 July 17th, 2008 01:04 AM
closed parent window when opened child window jaiwin Javascript How-To 0 October 8th, 2006 12:54 PM
how to destroy session when window is closed chayanvinayak PHP How-To 1 June 1st, 2006 06:18 AM
Determining if form is closed Paula222 Access VBA 2 April 17th, 2006 02:09 AM
return previous file after a window is closed hosefo81 PHP How-To 2 January 1st, 2004 02:13 AM





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