Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,956
    Thanks
    9
    Thanked 727 Times in 721 Posts
    window.onload is what you want. Have a look at this example, which looks like it does exactly what you're trying to do.

  • Users who have thanked SB65 for this post:

    JamesWP (07-18-2010)

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Superb, that's exactly what I needed. Thanks SB65!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •