This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Javascript function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript function" Watch "Javascript function" New topic
Author

Javascript function

Mark Butcher
Ranch Hand

Joined: Jun 28, 2012
Posts: 46
Hi everybody,

I want to invoke a javascript function just before a browser window is closed.
That means, if the user manually closes the browser window,
then that function should be called just before closing that window.
I tried html body "onunload" to call the function, but not working.

Thanks.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15379
    
    6
There is no real way of knowing if the person closes the window, refreshed the window, or navigates to a new page.

If you are trying to clean up a session on the server, that is what the session end events is for.

Eric
 
Consider Paul's rocket mass heater.
 
subject: Javascript function