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 August 16th, 2006, 11:03 AM
Authorized User
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Determine method of closing browser

I have created a Flash application that contains its own close button. When the use clicks this button, it saves a few final values to a database through an ASP page. If, however, the student chooses to close the browser either by using Alt-F4 or its X button, I'm unable to save the necessary data. So here's my question...

Is there a way to determine which method the user is trying to use to close the browser and display a message if one of the other methods is used?


Old August 24th, 2006, 10:23 AM
Friend of Wrox
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts


You can use the window object's onbeforeunload method to catch closures, but the problem is it also picks up on refresh too as it has to unload the page to reload it. Also, AFAIK there's no way to actually stop a window from closing once the user requests it. You could force the window to reopen but at the risk of losing any form data they may have inputted, but you could store this in cookies (if they have them enabled). There's questions all over google about this, but I've never seen anyone manage it. Surely you run the risk of annoying the crap outta your users though if they can't close their browser?


'sync' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
Old August 31st, 2006, 05:34 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

Hii chrscote!!
how this will help you

function saveData()
 //capturing ALT + F4
 if (event.altKey==true && event.keyCode==0 )

  // alert("closed2")


//or we can use body(unload) method


Cheers :)

Cheers :)


Similar Threads
Thread Thread Starter Forum Replies Last Post
closing browser prv299 ASP.NET 2.0 Professional 1 June 5th, 2008 09:15 AM
browser closing vamsivaila Pro Java 0 January 3rd, 2007 06:43 AM
Delete files on closing browser spacy ASP.NET 1.x and 2.0 Application Design 7 September 8th, 2004 04:24 PM
Closing browser using a Button MichaelTJ ASP.NET 1.0 and 1.1 Basics 3 December 18th, 2003 02:06 PM

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