[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How to know if a page is loaded (Ie my script was loaded after the onload event)

Posted on 2008-11-10
Medium Priority
Last Modified: 2012-05-05

I provide a script that has to start when the DOM is ready (OnLoad or OnDOMContentLoaded), but it is only executed in 3rd party webpages, so i don't know where it was put in the page or if it was even loaded by another js.

So I use an EventListener for OnLoad/OnDOMContentLoaded, but how do I know, if OnLoad has already triggered?

In Browsers which support document.readyState this is not a problem, but what about the others?

Thx in advance
Question by:ai-beng
  • 2

Author Comment

ID: 22920771
My solution is to use this function in Firefox (all other supported browsers support document.readyState ):

function onReady( pCallback )
        var oElem = document.createElement('a');
        document.body.appendChild( oElem );
        document.body.removeChild( oElem );
    catch( oException )
        setTimeout( function(){ onReady( pCallback ); }, 0 );

Author Comment

ID: 22928837
But my onReady-function is also not really acceptable, because it only means that the DOM is writeable, not that the complete page is loaded...
LVL 15

Accepted Solution

justinbillig earned 1500 total points
ID: 22940039
Unfourtunatly there is not going to be a solution that will catch every possible situation. If you can't enforce where in the page the user puts the script then there is no way to guarantee any situation.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question