Are you using jQuery? If so:
Code:
<script type="text/javascript">
jQuery(window).load(func);
</script>
Or if document ready which happens sooner is OK:
Code:
<script type="text/javascript">
jQuery(function($){
func();
});
</script>
Regular javascript:
Code:
<script type="text/javascript">
if (window.addEventListener){
window.addEventListener('load', func, false);
}
else if (window.attachEvent){
window.attachEvent('onload', func);
}
</script>
There's also:
Code:
<script type="text/javascript">
window.onload = func;
</script>
But that has almost as many problems as the <body onload="func();"> method does.
Or if you want to use document ready, place this before the closing </body> tag:
Code:
<script type="text/javascript">
func();
</script>
Aside from the last one (document ready, regular javascript), these may all go in the head or wherever pretty much and their code may go in an external file that's called, as long as they come after func() is defined.
There are variations on at least some of these methods, probably even other methods. But these should give you enough options to work with for now. If you have something in particular in mind and none of these seems ideal, let me know what the circumstances are.
Bookmarks