Fixes issues for window.onbeforeunload

https://developer.mozilla.org/en-US/docs/WindowEventHandlers.onbeforeunload
> Since 25 May 2011, the HTML5 specification states that calls to
window.showModalDialog(), window.alert(), window.confirm(), and
window.prompt() methods may be ignored during this event.