Have you tried jquery? Perhaps you could use the document.ready()? I believe if you do that, the javascript executes after the DOM (page) has loaded.
Example: (assuming of course you are including the jQuery library.)
<script type="text/javascript">
$(document).ready(function () {
});
</script>