• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

which event will fires before closing the browser window

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the javascript event you are looking for is onClose();
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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(); }
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic