Question

Is there any way to check that, web page is loaded 100 percent in javascript?

100 percent means all the images,files,scripts,styles everything that a web page contains.

Was it helpful?

Solution 2

You can use the window.onload function for that. E.g.

window.onload = function () { alert("It's loaded!") }

OTHER TIPS

if (document.readyState === "complete") {

}

That it what you need to check if the page is loaded for 100%.

If you want to trigger a function after the DOM Content is loaded, use:

document.addEventListener("DOMContentLoaded", function() {
  
});

Yes, window.onload:

window.onload = function () {
    // web page is loaded
}

What do you mean with 100% ?

You can verifiy that DOM is fully loaded with <body onreadystatechange="functionCalled();"> Or with jQuery syntax : $(document).ready(function() {});

But it won't wait for images, for instance.

EDIT

And if you want to check the readystate of dynamically loaded content, you still can use .ready method of jQuery. But you have to use it on the selector of what you load, not on body or window, or document.

$(document).ready(function() {
  ready=true;
  $('img,link').each(function() {
    if(!$(this).load(function() {
      ready=false;
    });
  });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top