Sometimes we have to capture page close event or navigation event to alert users. For example, Alerting user for navigating away from input page without saving it. Check this java script code..
if((window.event.clientX<0) || (window.event.clientY<0))
event.returnValue = "Are you sure you want to navigate away from this page? You haven't saved this form.";
This code works only in Ie6/7. And also keep in mind, we can never catch the browser close event for 100%. For example, what if the user kills the browser process or shut down OS.