Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which event will fires before closing the browser window

 
Venkata Ramana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the javascript event you are looking for is onClose();
 
Charlie Sturman
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4399
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Appleton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic