Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-18-2010, 07:31 PM   PM User | #1
JamesWP
New to the CF scene

 
Join Date: Jan 2007
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
JamesWP is an unknown quantity at this point
Question Autoloading a function without using BODY tag

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.
JamesWP is offline   Reply With Quote
Old 07-18-2010, 07:40 PM   PM User | #2
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
window.onload is what you want. Have a look at this example, which looks like it does exactly what you're trying to do.
SB65 is offline   Reply With Quote
Users who have thanked SB65 for this post:
JamesWP (07-18-2010)
Old 07-18-2010, 08:15 PM   PM User | #3
JamesWP
New to the CF scene

 
Join Date: Jan 2007
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
JamesWP is an unknown quantity at this point
Superb, that's exactly what I needed. Thanks SB65!
JamesWP is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:13 AM.


Advertisement
Log in to turn off these ads.