开发者

When does (mobile) Safari/Chrome consider a page loaded using Comet?

开发者 https://www.devze.com 2023-01-22 02:13 出处:网络
I have a website that uses a long-polling comet connection. The connection needs to be setup on/after page load.

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 mecha开发者_如何学Gonism, 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 :).


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消