Created
February 16, 2014 07:39
-
-
Save tanmaypatel/9030693 to your computer and use it in GitHub Desktop.
How to check if an HTML page is already loaded. Even after "load" event has dispatched!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This has been supported in IE and webkit for a long time. It was added to Firefox in 3.6. Here's the spec (http://www.w3.org/TR/html5/dom.html#dom-document-readystate). "loaded" is for older Safari browsers.*/ | |
if (document.readyState == "complete" || document.readyState == "loaded") | |
{ | |
// document is already ready to go | |
} | |
/* If you want to know when the page has been parsed, but all subresources have not yet been loaded, you can add the "interactive" value: */ | |
if (document.readyState == "complete" | |
|| document.readyState == "loaded" | |
|| document.readyState == "interactive") { | |
// document has at least been parsed | |
} | |
/* Beyond this, if you really just want to know when DOMContentLoaded has fired, then you'll have to install an event handler for that (before it fires) and set a flag when it fires. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment