View Full Version : Autoloading a function without using BODY tag

07-18-2010, 08:31 PM
The only way I know to make a script automatically run on the page is by using the "onLoad" property of the HTML body tag. However, I'm working with a template that serves the same header and footer for every page on my site, and this JavaScript is only needed on a single page. I therefore don't really want to edit the body tag with a function call that won't be needed in most cases.

To avoid doing this, is there any other way to make a piece of JavaScript run without input from the user? All I want to do is autofocus on a form field. Thanks for any advice.

07-18-2010, 08:40 PM
window.onload is what you want. Have a look at this example (http://javascript.about.com/library/blonload.htm), which looks like it does exactly what you're trying to do.

07-18-2010, 09:15 PM
Superb, that's exactly what I needed. Thanks SB65! :)