As far as I know, the only possible solution is to use the onbeforeunload
It wont completely restrict the user from closing the browser window which is not possible either from client side or from server side but it will prompt the user asking them
whether they really want to leave or stay back, which is probably the best cross
browser solution you can manage. As per the code the message returned will also be displayed along with the standard browser "Leave Page" confirm (the message wont be displayed in Firefox). Please check the updated code and have a look at the attached screenshot.
window.onbeforeunload = confirmExit;
"Any unsaved data will be lost"