Use low level dom event binding functions to bind the beforeunload handler to window.