window.onbeforeunload = WindowCloseHanlder;
window.alert('My Window is closing');
But I want to give the user options:
Your changes are not saved. Do you want to exit?
Yes - Should close the browser.
No - Should not close the browser and take the user back to the form.
Can I call a server-side function on close event so that I can display a custom message box?