javascript - 查看所有内容何时真正完成加载

标签 javascript jquery

是否有可靠的跨浏览器解决方案来查明网站上的所有 内容何时加载完毕?由于我有很多东西要加载(其中一些在 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/

相关文章:

php - Gmail Chat 如何在不进行长轮询的情况下向用户发送数据?

javascript - 类似 Python 的完整 Javascript 对象的 pickle

javascript - 面漆/电话间隙导航

javascript - 错误: listen EACCES IP:80 with ExpressJS and PM2

javascript - jQuery Textillate.js - 如何 "reset"元素 html 并重新启动动画

javascript - 辅助功能:aria-haspopup 可以用来做什么?

javascript - 如果生成的div具有相同的html内容,则只显示一个

php - 数据表按数字字段排序

javascript - 在下一行中插入新磁贴

javascript - 使用 Jquery 根据单击的菜单项切换类