How to avoid lost calls to an external JS file before loading it.
Posted
by
David
on Stack Overflow
See other posts from Stack Overflow
or by David
Published on 2011-01-08T19:26:26Z
Indexed on
2011/01/08
19:54 UTC
Read the original article
Hit count: 145
JavaScript
|object
Hi,
My issue is that multiple websites are going to include my JS file and when calling something like this:
<script src="..."></script>
hello.say("yay");
there going to be a race issue so sometimes it could make it sometimes not. i know that i can solve that easily by putting every function in a window.onload
but that wouldn't be clean as i've seen other websites magically solve that like google analytics:
.. Calling google analytics JS..
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-x"); <-- this an object !
pageTracker._trackPageview();
} catch(err) {}
</script>
How to do that?
© Stack Overflow or respective owner