5

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):

  1. Visit this page: https://web.archive.org/web/20211028110528/http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm
  2. Click on one of the links, you will get an alert asking you if you really want to leave this page
  3. Click "Stay On Page"
  4. Reload the page using cmd-R. You will be asked another time if you really want to leave the page
  5. Click "Stay On Page".
  6. 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 ?

Community
  • 1
  • 1
rpechayr
  • 1,282
  • 12
  • 27
  • It is weird, because even trying window.stop() won't make Safari stop pretending it's refreshing the page. I guess it is a bug, try reporting it to the [webkit guys](http://www.webkit.org/quality/reporting.html) – Roberto Feb 28 '12 at 01:44
  • It also happens if I refresh more than once. I don't need to click on one of the links. I'm running Safari 5.1.2 on a pc. – Alex Morales Feb 28 '12 at 12:20

2 Answers2

3

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:

  1. Visit the page in question.
  2. Hit reload.
  3. Click "Stay on Page" button.

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:

  • When dialog is dismissed with "Stay on page" button, it leaves the stopping X symbol on and the loading progress still engaged and frozen somewhere around 10% mark.
  • This "loading" can NOT be cancelled by any means (keyboard, button, script).
  • Network tab in Web Inspector asserts NO loading happening.

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.

Petr Vostrel
  • 2,324
  • 16
  • 23
0

Please see this page-> https://developer.mozilla.org/en/DOM/window.onbeforeunload

You must handle the event. The example at the page is working fine. Here is the code:

window.onbeforeunload = function (e) {
  e = e || window.event;

  // For IE and Firefox prior to version 4
  if (e) {
    e.returnValue = 'Any string';
  }

  // For Safari
  return 'Any string';
};
zipizip
  • 289
  • 2
  • 5
  • I was doubting about your answer in the first place. Then I thought that adding `(e)` instead of `()`would work. But this exact page https://gist.github.com/1960398 (taking exactly your js code) is showing the bug I am talking about in my question. – rpechayr Mar 02 '12 at 19:01
  • it was not 'my js code'. I gave the source as a link there if you could have checked it. – zipizip Mar 05 '12 at 13:43
  • Yes I also came across this code. Sorry for the my comment was not really clear. – rpechayr Mar 05 '12 at 19:36