Doctusoft/dsweb — pull request #73 by mterjeki (2014-12-29 20:25:40+00:00)
Title: added Onbeforeunload event

Probably it could be the best solution for handle this correctly:
http://stackoverflow.com/questions/14645011/window-onbeforeunload-and-window-onunload-is-not-working-in-firefox-safari-o
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.removeEventListener