How to track asynchronous scripts (that do not provide a callback)?
We are testing a new kind of advertising method that does call scripts asynchronously but they DO NOT provide a callback for anything. We want to track the loading time of this new method after it has finished loading and written new elements into a div or something.
Is the only way to do this to lookin开发者_JS百科g for a change in the number of children of this specific element via setTimetout()? What other do I have to do this?
I missed an existing Stack Overflow answer to this question, I apologize in advance.
It appears there is an onload event for the script, and also an onreadystatechange event. IE uses the readystate event, others use onload. See article for details.
http://unixpapa.com/js/dyna.html
var script = document.createElement('script');
script.type= 'text/javascript';
script.async = true;
script.onreadystatechange= function () {
if (this.readyState == 'complete') complete();
}
script.onload= complete;
script.src = 'some.js';
精彩评论