| Author |
which event will fires before closing the browser window
|
Venkata Ramana
Greenhorn
Joined: Feb 14, 2002
Posts: 17
|
|
Hi When i close the browser window using the 'X' in the top right hand side of the browser window, i want to execute a method of javaScript. Which event i need to use. Ramana
|
 |
Eric Peterson
Ranch Hand
Joined: Jan 08, 2002
Posts: 31
|
|
|
I believe the javascript event you are looking for is onClose();
|
Eric Peterson
|
 |
Charlie Sturman
Ranch Hand
Joined: Apr 04, 2002
Posts: 112
|
|
Originally posted by Ramana: Hi When i close the browser window using the 'X' in the top right hand side of the browser window, i want to execute a method of javaScript. Which event i need to use. Ramana
javascript: window.onunload = function(){ alert(); }
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
Use can use onload attribute in the body tag to specify the method to be executed. But remember the event onunload gets fired when the refresh/reload button of the browser get clicked.
|
Groovy
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
The event is onunload and not unload as written by me in my previous post.
Originally posted by pradeep bhat: Use can use onload attribute in the body tag to specify the method to be executed. But remember the event onunload gets fired when the refresh/reload button of the browser get clicked.
|
 |
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 4089
|
|
Ramana, I hate to say this but, your name does not comply with the Javaranch naming guidelines which can be found at http://www.javaranch.com/name.jsp please register again with a valid name.
|
SCJP
|
 |
Dave Appleton
Greenhorn
Joined: Jan 20, 2002
Posts: 2
|
|
The way to detect if a wiindow is closed is with an unload function and some extra checking of the event object function onClose() { if ((window.event.clientX<0) && (window.event.clientY<0)) alert("you closed me"); } ... <body onunload="onClose()"> Have Fun.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
PLEASE LOOK AT THE DATE this post was posted April 14, 2002. I really doubt a person needs the answer anymore! Eric [edit]Plus if I remember correctly this solution you proposed only works in IE[/edit] [ December 21, 2003: Message edited by: Eric Pascarello ]
|
 |
Brendan Caffrey
Greenhorn
Joined: Jan 07, 2004
Posts: 1
|
|
The question may have been old - but the most satisfactory answer ( in my case anyway) was that provided by Dave Appleton. Surely adding new and correct information can't be a bad thing.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
The answer is not a cross browser supported answer plus I can give that answer to anyone that asks. Plus since no one seems to know what a search button is lately I doubt they would have found the answer. I have people come in here before and answer 15 questions that were posted way in the past, I do not want that to be a habit of new posters. If you used the submit button, I would be impressed. Eric [ January 07, 2004: Message edited by: Eric Pascarello ]
|
 |
 |
|
|
subject: which event will fires before closing the browser window
|
|
|