webworkflow warn before leaving page during upload #9625
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resolves: #9606
There turned out to be two different cases to handle for this:
For 1 the solution of adding the event listener for
beforeunload
event and then preventing the default behavior causes the alert to the shown to the user confirming whether they want to leave. As far as I understand it, it's not longer possible to customize the message in that confirmation it will always be a generic message, in the past it was possible, but not in modern browsers.For 2 since the page doesn't technically change it doesn't trigger the event. I tried for a bit to dispatch the beforeunload event "manually" but it wasn't working. In the end I realized that we could make the upload succeed instead of fail by storing the value of
current_path
into a local variable and using it throughout the rest ofupload()
rather than getting the value from the possibly changed by user actioncurrent_path
variable. With this change when the user navigates to a new directory the upload just continues working and the remaining files succeed to upload, so there is no need to warn the user about leaving the page since technically the aren't, and now the remaining uploads can succeed.