-
Notifications
You must be signed in to change notification settings - Fork 622
onbeforeunload on back button - prevent user from losing unsaved changes #264
Comments
+1 Also trying to solve this problem |
+1 trying to exit full screen in player on back button instead of navigation to previous page |
+1 Having the same problem showing a confirm dialogue before leaving a page via back button. |
Has been this solved?, I have the same issue pressing the back button. 🙁 |
@maguri drop it :) |
@timonbandit ,Where is this "realization"? |
@maguri in private repo ;) |
Yeah sure, Thanks @timonbandit 🤙🏼 ! |
@maguri 👍 |
[DEPRECATED] JQuery This has resolved my need: |
@maguri How do you cancel navigation? |
Problem is turbolinks:before-visit isn't fired for back button and window.onpopstate don't prevent turbolinks from navigation. |
+1 Having a similar issue. Any ideas? |
Just run into this as well. The docs for On closer inspection, because |
There doesn't seem to be any way to prevent Turbolinks from reloading and replacing the entire browser window when a user clicks Back (since turbolinks:before-visit is not triggered for _when navigating by history_), So, rather than hiding the displayed modal when clicking Back (and then having to reload the page), we keep the Modal displayed while Turbolinks does its stuff in the background (including progress bar). See turbolinks/turbolinks#264 for a related issue (suggested `turbolinks:before-history-change` event).
@andypearson is correct: Turbolinks clones the |
I saw #146 and #216 but still can't find a way to solve a simple requirement: show an alert asking the user to confirm navigating away if he has unsaved changes.
If I bind
$(window).on('beforeunload' ...
, it will fire when reloading the page, clicking a bookmark or typing a new url in the addressbar, but it won't fire on back button (and also, obviously, won't fire on clicking on internal links).If I also bind
$(document).on('turbolinks:before-visit', function(event) { ... }
, this solves the internal links (I can show a confirm alert and useevent.preventDefault()
to stop navigation if there are unsaved changes), but this also won't fire on browser back button.The suggestion in #146 suggests binding to
$(document).on('turbolinks:before-render'
, but I can't seem to find a way to show the dialog and cancel navigation if the users clicks cancel, asevent.preventDefault()
doesn't cancel navigation inturbolinks:before-render
So: how to prevent user from losing unsaved changes when he uses the back button ?
The text was updated successfully, but these errors were encountered: