Safari 保持“正在加载”状态当 window.onbeforeunload 返回 false 时

发布于 2025-01-08 02:58:06 字数 856 浏览 0 评论 0原文

以下要点: https://gist.github.com/1876791 (借自 < a href="https://stackoverflow.com/questions/147636/best-way-to-detect-when-user-leaves-a-web-page">这个问题) 是一个在 js 中使用 window.onbeforeunload 的简单示例。

我们遇到的问题如下(发生在 Safari 5.1.3 上,而不是最新的 Chrome 版本):

  1. 访问此页面:https://web.archive.org/web/20211028110528/http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm
  2. 单击其中一个链接,您将收到一条警报,询问您如果您确实想离开此页面,
  3. 请单击“留在页面上”
  4. 使用 cmd-R 重新加载页面。系统将再次询问您是否确实要离开该页面,
  5. 然后单击“留在页面上”。
  6. Safari 保持“正在加载”状态,进度条显示好像要加载下一页。

这是 Safari 的错误吗?有没有办法绕过这个问题?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅黛梨妆こ 2025-01-15 02:58:07

请看此页-> https://developer.mozilla.org/en/DOM/window.onbeforeunload

您必须处理该事件。该页面上的示例运行良好。这是代码:

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';
};

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';
};
維他命╮ 2025-01-15 02:58:06

即使跳过 OP 的步骤 2 和 3,我也能够重现此问题。任何形式的重新加载都会出现此问题。重现的简约步骤:

  1. 访问 页面问题
  2. 点击重新加载。
  3. 单击“留在页面上”按钮。

加载进度在重新加载命中后立即在视觉上预先进行,并在确认对话框的整个生命周期中保持如此(显然是为了传达“悬挂在悬崖边缘”类型​​的成熟情况;)但是:

  • 当对话框使用“留在页面上”按钮关闭,它会保留停止 X 符号,并且加载进度仍然处于工作状态并冻结在 10% 左右的位置。
  • 无法通过任何方式(键盘、按钮、脚本)取消此“加载”。
  • Web Inspector 中的“网络”选项卡断言没有发生加载。

这确实看起来像一个 Webkit/Safari UI 错误 - 它看起来无法在停留在页面的情况下脱离进度条。最好的办法是向 Webkit 团队报告,或者,因为您在 Safari 中遇到过这种情况,也许 Safari 团队会更好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文