How does js determine that all page content is loaded? How does js determine that all page content is loaded?
Reply content:
How does js determine that all page content is loaded?
See how to explainContent
These two words.
For pages,dom
The structure, style, and script also belong to the content, and the image, text, video, and audio on the page are also the content.
So we often usewindow.onload
Andjquery
Inready
Can the function determine whether all content is loaded? The answer is:No. The preceding two operations can only determine whether the page skeleton is loaded, but cannot determine whether the page resources are loaded, such as ultra-large images and videos on the page. In addition, resources with asynchronous requests cannot be detected, especially inonload
The request that occurs later.
So what I said on the first flooronreadystatechange
Can callback be processed? This does not seem to work either. The reason is that the onreadystatechange event-w3school.
This article clearly explains that when a request occursreadyState
Will change and triggeronreadystatechange
So the question is, when do you know all the requests have been loaded? Especially time-consuming resources?
So, the conclusion is: why do we need to check that all the content has been loaded? If you need dynamic Processingdom
Inonload|ready
In, because the pagedom
The load has been completed. If you need to monitor some asynchronous requests, you only need to add a callback to the corresponding asynchronous request.
Errors
Above.
This kind of problem self Baidu look up: http://bbs.csdn.net/topics/350132930
Document. onreadystatechange = subSomething; // This method is executed when the page loading status changes.
Function subSomething ()
{
If (document. readyState = "complete") // when the page is loaded
Myform. submit (); // form submission
}
I think you mean window. onload. In fact, the content contains too many things. In fact, the first floor has already been clearly stated. In fact, it is a method. setTimeout doesn't work either. I just want to give a comment, read the answer on the first floor.
Window. onload: this can solve your concerns, because it is activated after the browser parses the DOM structure and downloads the image and other content.
JQuery's document. ready is activated after the browser parses the document structure. At this time, the image may not be fully loaded, so the time point is earlier than window. onload.
Window. onload is what the landlord needs