javascript jQuery - 如何检测页面何时完成加载?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12230867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:40:18  来源:igfitidea点击:

jQuery - How to detect when page is finished loading?

javascriptjqueryhtml

提问by omega

How can I detect if the page is finished loading completely? I say completely because I tried putting an alert statement in the $(document).ready(function()code, but the alert statement happens before the wheel stops spinning in IE (After like 1.5 seconds, the wheel stops, and that's when the page is completely loaded). (its the loading wheel you see in the top of IE9 where the tab is).

如何检测页面是否完全加载完成?我说完全是因为我尝试在$(document).ready(function()代码中放置一个警报语句,但警报语句发生在 IE 中的轮子停止旋转之前(大约 1.5 秒后,轮子停止,那是页面完全加载的时候)。(它是您在 IE9 顶部看到的选项卡所在的加载轮)。

Thanks

谢谢

回答by undefined

You can use loadmethod:

您可以使用load方法:

The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading.

load 事件在文档加载过程结束时触发。至此,文档中的所有对象都在DOM中,所有的图片和子框架都已经加载完毕。

$(window).load(function(){
    // ...
})

回答by Gabe

$(window).load(function() {
// do stuff 
});

回答by The Alpha

Try

尝试

$(window).load(function(){
    //....
});

The document readyevent executes already when the HTML-Document is loaded and the DOM is ready, even if all the graphics haven't loaded yet and the window loadevent executes a bit later when the complete page is fully loaded, including all frames, objects and images.

document ready当 HTML 文档加载完毕且 DOM 准备就绪时,该事件已经执行,即使所有图形尚未加载,并且window load在整个页面(包括所有框架、对象和图像)完全加载后,该事件也会稍后执行。

回答by Jo?o Silva

Try using the window.onloadevent.

尝试使用该window.onload事件。

回答by Ashirvad

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

Above function guarantees that the DOM is ready to be modified by javascript. It does not guarantees about the xhr request which are asynchronous in nature to load.SO there might be situation that some xhr request is happening and the spinner shows loading untill there is no http request in progress.

以上函数保证了 DOM 已准备好被 javascript 修改。它不保证本质上异步加载的 xhr 请求。所以可能会出现一些 xhr 请求正在发生并且微调器显示加载直到没有正在进行的 http 请求的情况。