Re: [back] event

I wrote a few paragraphs, and then realized I misunderstood your
scenario, but maybe you can clarify that during our next call.

From a web API perspective, navigation is a little tricky these days. The
common way to deal with this scenario, if I understand what you mean, is to
install an `unload` handler which asks for confirmation to the user. I
don't think there is a way for the app to just receive an event. But
installing such a handler breaks/disables the bfcache [1], which is not
good practice, so the handler should be installed dynamically, only when
the application state is unsaved.

But maybe there is a workaround, for example by adding a dummy entry with
the History API [2], and then catching a history state change. If data is
unsaved, then ask the user for confirmation, save, and maybe go back.

I am not sure if that can work, and there is also the question of whether
hijacking the back button this way would be a good idea from a web browser
experience point of view. I think that most modern apps would tend to
autosave data and use the dynamic `unload` handler to catch cases where the
data is not yet saved.

-Erik

[1] https://web.dev/articles/bfcache
[2] https://developer.mozilla.org/en-US/docs/Web/API/History_API

On Tue, Dec 26, 2023 at 8:35 AM Steven Pemberton <steven.pemberton@cwi.nl>
wrote:

> In an app I'm building, I really need to catch the [back] button, since
> that is such an obvious action within the app, which otherwise causes the
> app to exit.
>
> It seems like a good candidate for an event.
>
> Steven
>
>

Received on Friday, 5 January 2024 02:54:16 UTC