1

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.

Dixit Singla
  • 2,540
  • 3
  • 24
  • 39

4 Answers4

8
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() {
  
});
Daan
  • 2,680
  • 20
  • 39
  • Doesn't wait for anything but the DOM. Please note the question was updated. – John Dvorak Feb 20 '14 at 13:30
  • @JanDvorak He didn't ask for a code that would wait for the document to fully load, he asked for a way to check if the page loaded. Which can be done with `if (document.readyState === "complete") { }`. Please read the question before downvoting my answer. Also, if the `document.readyState` is set to `complete` it means everything is loaded (100%). – Daan Feb 20 '14 at 13:32
  • 1
    Removed my vote because you removed `$(document).ready`. That second part indeed wasn't what the asker wanted. – John Dvorak Feb 20 '14 at 13:40
  • can we get the percentage of resources loaded? like images,scripts etc etc? – techie_28 Mar 30 '16 at 09:54
3

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

window.onload = function () { alert("It's loaded!") }
Sidney Gijzen
  • 1,931
  • 3
  • 24
  • 27
1

Yes, window.onload:

window.onload = function () {
    // web page is loaded
}
GiveMeAllYourCats
  • 890
  • 18
  • 23
0

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;
    });
  });
});
vekah
  • 980
  • 3
  • 13
  • 31