Is there an equivalent "Window: beforeunload event" that can be used in elm programming?

68 Views Asked by At

I want to trigger a Browser dialog when the user is about to close the tab or navigate from the current page. I cant find an equivalent "Window: beforeunload event" in elm. The Browser.Events provided by elm packages only detects tab changes, and not tab closes. How can I detect when a tab is about to be closed or when the user wants to navigate away from the current page in elm?

1

There are 1 best solutions below

0
bdukes On

You'll need to use ports to integrate with the beforeunload event (or register an event handler totally outside of the Elm app).