use `window.onbeforeunload=` for nav-away warning

Firefox 22 broke `$(window).on("beforeunload")` somehow, for some reason, resulting in always showing a dialog, regardless of the function's return value.

closes #3509

The only fix I could find was resorting to the basic low-level API.