 <p>Typically, I attach an event to the <code>onload</code> event of the window. This will be fired whenever all the resources <em>initially present</em> on the page have loaded (css/html/images/sounds/videos).</p> <p>To do this, you simply need do the following:</p> <p><code>window.addEventListener('load', onDocLoaded, false);</code></p> <p>Next, you need a function that will actually handle this event:</p> <pre><code>function onDocLoaded(evt) { /* initialization code goes here */ } </code></pre> <p>In your case, you'd just need to add a call to the <code>exludeUserAgent</code> function to the body of <code>onDocLoaded</code>.</p>