This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.