Javascript-how to determine if all the page content is loaded?

Source: Internet
Author: User
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 explainContentThese two words.

For pages,domThe 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.onloadAndjqueryInreadyCan 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 inonloadThe request that occurs later.

So what I said on the first flooronreadystatechangeCan 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 occursreadyStateWill change and triggeronreadystatechangeSo 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 ProcessingdomInonload|readyIn, because the pagedomThe 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
}

  • window.onloadPage (including resources) Ready

  • document.onloadDOM loaded

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.