5
votes
Prompt for unsaved changes on iOS?
I was just writing a different long post here and lost it all because of accidental navigation away from the page. I know the feature to prompt for unsaved changes works on desktop, but is there any way to get it working on iOS?
Edit: maybe another solution would be to save one new topic draft in local storage, and clear the draft data on click of Save or a new Discard/Cancel button? This way if there was data on load of the new topic page, it would still be there.
Ah, sorry for the lost post. I filed an issue for this way back in July, but hadn't fixed it yet: https://gitlab.com/tildes/tildes/issues/155
Let me take a look now and see if I can figure out an easy way to get it to work.
Thanks! I searched issues but apparently quite poorly :)
Safari on iOS does not support
onbeforeunload
[1]. However, there may be ways to get around it with a combination of other events[2][3].[1] https://stackoverflow.com/a/6907676/5203655
[2] https://stackoverflow.com/a/26193484/5203655
[3] https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5
[3] https://html.spec.whatwg.org/multipage/indices.html#event-pagehide
Thanks for the solid reply! And just to clarify, I tried on iOS chrome too, so this is a WebKit issue?
Yes, all browsers on iOS are required to use WebKit as the engine, per the Apple developer ToS
Is there a site like caniuse which specifies that iOS Safari does not support
onbeforeunload
? That's where I looked, and they say it's in all modern browsers, not making the iOS distinction which is important here.MDN's Browser Compatibility list for it has "No" under Safari on iOS: https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#Browser_compatibility
I just tried making a change that might fix this, but I can't test it myself.
@Neverland (or anyone else that's using the site through mobile iOS), could you try entering some text into a comment box now and then clicking on a link or pushing back, and see if it stops you from navigating away with a prompt? You may need to force a full refresh first to make sure you have the new javascript.
Thanks for trying (@Neverland too). It looks like this method won't work then (and I've reverted the change I tried).
At least as far as I can tell from looking for workarounds so far, it's not even going to be possible to do "pop up a warning before leaving the page" on iOS. I might be able to store the comment and restore it if you come back, but that will require more work since it's an entirely new feature.
Yeah, I thought some sort of saved draft feature might be needed. Well thanks for investigating more fully.
Just my 2c on priority, that is the only thing that is lacking in my Tildes iOS mobile experience. So in my mind restoring the draft new_topic would be very nice to have/almost “broken.” It sucks that it would be work, add complexity, and address a need of only iOS users.
I'd just want to store the text in the browser's storage, not on Tildes's end. I don't think unfinished posts should leave your browser (and if they did, it would probably be through a more explicit "drafts"-like feature, which would definitely be opt-in to use).
It also does not work for me, and I tried in a Chrome incognito tab to make sure I had the latest code.