API for window.beforeunload that also works with Turbolinks.