I have a click
event that is triggered from another place automatically for the first time. My problem is that it runs too soon, since the required variables are still being defined by Flash and web services. So right now I have:
(function ($) {
$(window).load(function(){
setTimeout(function(){
$('a.play').trigger("click");
}, 5000);
});
})(jQuery);
The problem is that 5 seconds for a person with a slow internet connection could be too fast and vice versa, for a person with a fast internet connection, it's too slow.
So how should I do the delay or timeout until someVariable
is defined?
You could have Flash call the function when it's done. I'm not sure what you mean by web services. I assume you have JavaScript code calling web services via Ajax, in which case you would know when they terminate. In the worst case, you could do a looping
setTimeout
that would check every 100 ms or so.And the check for whether or not a variable is defined can be just
if (myVariable)
or safer:if(typeof myVariable == "undefined")
You can use this:
Instead of using the windows load event use the ready event on the document.
This should fire when everything in the DOM is ready to go, including media content fully loaded.