This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt 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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript function" Watch "Javascript function" New topic

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.

Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
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.

I agree. Here's the link:
subject: Javascript function
It's not a secret anymore!