Is there a definitive JavaScript method for checking whether or not a web page has loaded completely? Completely, meaning 100% complete. HTML, scripts, CSS, images, plugins, AJAX, everything!
As user interaction can effect AJAX, let’s assume there is no further user interaction with the page, apart from the initial page request.
What you’re asking for is pretty much impossible. There is no way to determine whether everything has loaded completely. Here’s why:
onload(orDOMReady) event fires, making the method of using theonloadevent to see if the page has loaded impossible.window.XMLHttpRequest, but you still couldn’t tell if plugins like Flash were still loading or not.The only way to know for sure that everything loaded is to have every single piece of code on the page that loads something tell your code that it has finished once it loads.
A hacky, incomplete solution: You could try overriding
XMLHttpRequestwith a function that wraps the existingXMLHttpRequestand returns it. That would allow you to tell if a AJAX event is currently taking place. However, that solution wouldn’t work for seeing if plugins are loaded, and you wouldn’t be able to tell the difference between AJAX events that are triggered at page load and AJAX requests that happen periodically, like the ones on Stack Overflow that change the Stack Exchange icon on the top-left if you have new notifications.Try something like this: