Meaningless Drivel is fun!
The moose likes HTML, CSS and JavaScript and the fly likes how to detect Browser close Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to detect Browser close" Watch "how to detect Browser close" New topic

how to detect Browser close

Ahmed M. Omar
Ranch Hand

Joined: Mar 02, 2010
Posts: 43
I need to detect the event when the browser close BUT I NEED A PROFESSIONAL SOLUTION.

all of the solutions available on the internet (depending on client coordinates and on load and on unload) are fake

please i need a real solution to that problem
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

There isn't a reliable way to know if a browser has closed.

Browsers crash, operating systems crash, network connections crash.
There are many situations where a browser will not be able to communicate a problem to the server.
Your server application should not rely on being able to tell if the user is still looking at your application.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

The best solution is to use the onbeforeunload event however, I suspect it won't work as you want it to. There isn't a great solution to this problem.

GenRocket - Experts at Building Test Data
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Ahmed M. Omar wrote:I need to detect the event when the browser close BUT I NEED A PROFESSIONAL SOLUTION.

There is not one. Session End on the server is your friend for a reason.

David Newton

Joined: Sep 29, 2008
Posts: 12617

Heck, some of my "web browsing" doesn't involve a browser anymore; I'm not sure how much, but I know it's gone up quite a bit.
Have you checked out Aspose?
subject: how to detect Browser close
It's not a secret anymore!