The following gist: https://gist.github.com/1876791 (borrowed from the demo in this question)
is a dead simple example of usage of window.onbeforeunload in js.
The problem we have is the following (Happens with Safari 5.1.3 and not Latest Chrome version):
- Visit this page: https://web.archive.org/web/20211028110528/http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm
- Click on one of the links, you will get an alert asking you if you really want to leave this page
- Click “Stay On Page”
- Reload the page using
cmd-R. You will be asked another time if you really want to leave the page - Click “Stay On Page”.
- Safari stays in a “loading” status, with the progress bar showing as if it were to load the next page.
Is this a bug from Safari ? Is there a way to circumvent this problem ?
I was able to reproduce this issue even while skipping OP’s steps 2 and 3. Any form of reload exhibits this issue. Minimalistic steps to reproduce:
The loading progress is visually pre-engaged right after the reload hit and stays so for the entire life of the confirm dialog (apparently in an effort to communicate the “hanging over cliff edge”-type mature of the situation 😉 However:
Xsymbol on and the loading progress still engaged and frozen somewhere around 10% mark.This really looks like a Webkit/Safari UI bug – it looks to fail to disengage the progress bar in stay-on-page conditions. Best would be to report it to the Webkit team or, since you experience this in Safari, maybe the Safari team would be better.