Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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 June 30th, 2004, 12:15 AM
Registered User
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Handling window unload event

Can any body help !
I would like to display a message when the user clicks on the "X" button of the browser. for that, I have used onUnload event and in that I am displaying an alert message. This works fine if I click "X". But, even if I refresh the page or if I click any action on the page, same onUnload method is fired. How to restrict my action only to "X" button click?
Thank you,
Old June 30th, 2004, 01:03 AM
Friend of Wrox
Join Date: Jun 2004
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi

you can use windows.close() method for this

Love 4 all
Old June 30th, 2004, 10:59 AM
Friend of Wrox
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts


I believe MurthyGarimella wishes to cause an event to fire when the window closes, not refreshes. window.close() closes the window.


There is a way to do this but it requires some coding and has some severe limitations....

You must somehow disable the refresh button, for example by opening a window without it. However, you can never FULLY disable it; a user can always press F5 or something.

Create a frames page with the onUnload event attached. You only need to make one frameset with one frame in it. Put your page in that one frame.

If this is acceptable to you, try it and tell me if it's what you need.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Event handling in c# bhavna General .NET 1 March 7th, 2007 05:32 AM
Event Handling Bill Crawley ASP.NET 2.0 Basics 0 February 28th, 2007 07:32 AM
Detect when window closes, not unload Snib Javascript How-To 11 October 24th, 2006 01:14 AM
on window unload event in javascript. babu17 Classic ASP Basics 1 April 15th, 2006 05:48 AM
Interrupting DoCmd.Close & Form Unload Event SerranoG Access 2 November 19th, 2005 03:41 PM

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