(移动)Safari/Chrome 何时考虑使用 Comet 加载页面?

发布于 2024-09-28 08:11:32 字数 476 浏览 2 评论 0原文

我有一个使用长轮询彗星连接的网站。需要在页面加载时/之后设置连接。

尽管我努力阻止它,但许多浏览器仍将长轮询请求视为页面加载机制的一部分,从而使页面保持在“加载”阶段。在 Safari 中,这会导致进度条(位于 url 字段后面)无法完成。在 Chrome 中,网站图标显示为旋转的加载图标。更成问题的是 iPhone 上的移动 Safari,它不允许在“加载”时隐藏 url 字段。移动 Android 在某些设备上也存在类似问题。

总而言之,该行为很难重现,并且似乎取决于浏览器/平台/连接速度/等。现在,我的代码在 window.onLoad 触发后 10 毫秒启动长轮询。这似乎经常有效,但并非总是如此。我怀疑它可能与加载一些外部(图像/javascript)资源有关,但有人会说 onLoad 事件是在这些资源完全加载后触发的。

有人知道如何强制这些浏览器考虑我的页面已加载吗?理想情况下,人们可以以某种方式将 xmlhttprequest 标记为类似彗星,但这不是一个功能:)。

I have a website that uses a long-polling comet connection. The connection needs to be setup on/after page load.

Despite my efforts to prevent it, many browsers consider the long-poll request to be part of the page loading mechanism, thus keeping the page in a 'loading' phase. In Safari this results in the progress bar (behind the url field) to not complete. In Chrome the favicon is shown as a spinning loading icon. Even more problematic is mobile safari on iphone, that does not allow hiding the url field while 'loading'. Mobile android has similar issues on some devices.

All in all, the behavior is difficult to reproduce and seems to be dependent on browser/platform/connection speed/etc. Right now, my code initiates the long polling 10msecs after the window.onLoad trigger. This seems to work well often, but not always. I suspect it may have something to do with loading some external (image/javascript) resources, yet one would say the onLoad event is fired after these are completely loaded.

Anyone some pointers on how to force these browsers into considering my page as loaded? Ideally, one could somehow mark an xmlhttprequest as comet-like, but this is no feature :).

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

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

发布评论

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

评论(2

黎歌 2024-10-05 08:11:32

我遇到了同样的问题,发现如果您在发出长轮询 ajax 请求之前允许页面退出其 onload 处理程序,则一切正常,并且页面不会返回到加载状态。

例如,通常的

$(document).ready(function() { $.ajax(...); });

将变为

$(document).ready( function() setTimeout(function() { $.ajax(...); }, 0);

在 WebKit 的特定情况下,我相信 $(document).ready 是同义词窗口.onload。这就是为什么它很重要。

这对我在装有 iOS 5 的 iPad1,1 上有效。

I've been having the same issue and found that if you allow the page to exit its onload handler before issuing your long polling ajax request, everything works fine and the page does not go back into a loading state.

So for example, what usually would be

$(document).ready(function() { $.ajax(...); });

would become

$(document).ready(function() setTimeout(function() { $.ajax(...); }, 0); });

In the particular case of WebKit, I believe that $(document).ready is a synonym for window.onload. So that's why it matters.

This worked for me on iPad1,1 with iOS 5.

风吹雨成花 2024-10-05 08:11:32

我们已经成功地通过 ajax 长轮询请求删除了 Safari 5.1.5 中的“正在加载”指示器。不幸的是,Chrome 仍然始终显示加载指示器。对于 chrome,我们的团队选择简单地更改整个 body 元素上的 css 光标值(例如:十字线或自定义光标) - 一个可怕的“黑客” - 但至少用户在加载时不会看到加载鼠标光标都在系统上。

We have been successful removing the "loading" indicator in Safari 5.1.5 with ajax long polling requests. Chrome unfortunately still consistently shows the loading indicator. For chrome, our team has chosen to simply change the css cursor value on the entire body element (ex: crosshair or a custom cursor) - a terrible "hack" - but at least the user won't see the loading mouse cursor while they are on the system.

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