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


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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ai-bengAuthor Commented:
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 );
ai-bengAuthor Commented:
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...
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.