How to determine if a webpage is fully loaded in a web browser?

I am working on a Windows Form application, which is the basic HTML user interface. I need to know when the webpage is fully loaded. I tested many events in a web browser, such as DocumentCompleted, IsBusy, ReadyState, but none of them answered what I expected.

+4
source share
2 answers

If you can use jQuery library then it is really simple.

$(document).ready() { //your page is fully loaded }; 

Otherwise, you will have to rely on various methods based on the browser you are using. Since this is a Windows form application, I assume that the rendering engine you are using is based on IE. If this is then this may work for you:

 if (document.attachEvent) { document.attachEvent("onreadystatechange", function() { if (document.readyState === "complete") { document.detachEvent("onreadystatechange", arguments.callee); /* code to run on load */ } }); } 

Here you can find other browser-dependent solutions if you are interested: http://dean.edwards.name/weblog/2006/06/again/

+3
source

Chamika Sandamal is right - you should use the DocumentComplete BUT event - check the 'sender' object. The most recent “complete” event comes from the “browser” itself, and not from images, text, etc., which trigger it upon loading. After all the elements on the page fire the DocumentComelete event, the most recent event will come from the browser itself. If you can impose a "sender" on the browser object, here you go - it loads the completion of the download by the browser. Just note that if you have any "frame" tags in HTML, they will raise various DcoumentComplete events after the "Full Browser" event has ended. I think the “frame” is treated like another HTML page, so it will have “full” events.

0
source

Source: https://habr.com/ru/post/1397170/


All Articles