是否有可靠的跨浏览器解决方案来查明网站上的所有 内容何时加载完毕?由于我有很多东西要加载(其中一些在 iframe 中),这实际上不起作用(即使浏览器的加载指示器仍在旋转,事件也会被触发):
$(window).add('iframe').bind('load').promise().done(function() {
alert('Too early :(');
});
最佳答案
我实际上正在使用这个:
$(window).load(function () {
// loading done, now perform for example animate/remove loader icon.
});
您可以在这里阅读更多相关信息:
http://api.jquery.com/load-event/
还有一个警告:
Caveats of the load event when used with images
A common challenge developers attempt to solve using the .load() shortcut is to execute a function when an image (or collection of images) have completely loaded. There are several known caveats with this that should be noted. These are:
It doesn't work consistently nor reliably cross-browser
It doesn't fire correctly in WebKit if the image src is set to the same src as before
It doesn't correctly bubble up the DOM tree
Can cease to fire for images that already live in the browser's cache
我在现代浏览器上使用它,在 mac/win 上,到目前为止没有发现任何问题
关于javascript - 查看所有内容何时真正完成加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8198598/