Safari 保持“正在加载”状态当 window.onbeforeunload 返回 false 时
以下要点: 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 版本):
- 访问此页面:https://web.archive.org/web/20211028110528/http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm
- 单击其中一个链接,您将收到一条警报,询问您如果您确实想离开此页面,
- 请单击“留在页面上”
- 使用
cmd-R
重新加载页面。系统将再次询问您是否确实要离开该页面, - 然后单击“留在页面上”。
- 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):
- 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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请看此页-> https://developer.mozilla.org/en/DOM/window.onbeforeunload
您必须处理该事件。该页面上的示例运行良好。这是代码:
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:
即使跳过 OP 的步骤 2 和 3,我也能够重现此问题。任何形式的重新加载都会出现此问题。重现的简约步骤:
加载进度在重新加载命中后立即在视觉上预先进行,并在确认对话框的整个生命周期中保持如此(显然是为了传达“悬挂在悬崖边缘”类型的成熟情况;)但是:
X
符号,并且加载进度仍然处于工作状态并冻结在 10% 左右的位置。这确实看起来像一个 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:
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:
X
symbol 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.