I add an event lister on beforeunload
as customary in my JS/ReactJS application. The function adds a confirmation dialog depending on an internal unSaved
state.
Everything works fine on Chrome and Firefox (macOS / desktop).
On Safari, however:
- the first time "I make use" of the event handler (I leave the page while
unSaved==true
), it works fine as expected, - yet, in subsequent attempts of leaving the page with
unSaved==true
, Safari does not ask for any confirmation at all. - when I go to a new tab (with the same previous URL), again the first time works, subsequent times do not...
What is weirder: I can see that my added event function is actually being called every time on safari since a test console.log
is indeed being printed every time.
My only possible guess is that Safari is somehow caching my confirmation response for the tab? (?)
Any ideas for how to solve this?
My stack:
Safari: Version 10.0.1 (12602.2.14.0.7)
macOS: 10.12.1 (16B2657)
host: localhost
protocols: tested on both, http and https
More info:
- event
pageshow
has the propertypersisted
always set to false. Therefore, the Page Cache by Safari (BFCache) should not be the cause of the problem.