Results 1 to 3 of 3

Thread: [RESOLVED] trigger javascript onload from an include file?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Resolved [RESOLVED] trigger javascript onload from an include file?

    I have a main page that has a couple of requires.

    In one of those requires, I want to trigger a javascript onload. Is there any code to trigger a javascript on load, without adding it at the opening <body> tag?

    Thanks
    HoraShadow
    I do like the reward system. If you find that my post was useful, rate it.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: trigger javascript onload from an include file?

    Event handler registration should always be done exclusively through the Javascript code files (you do have them in separate files right? Good) using addEventListener() and its sad cousin required for IE compatibility, attachEvent().

    So, for a load event handler:
    Code:
    if (window.addEventListener)
      window.addEventListener('load', doOnload, false);
    else if (window.attachEvent)
      window.attachEvent('onload', doOnload, false);
    
    function doOnload(e)
    {
      // ...
    }
    You could also grab my event registration wrapper which reduces the process to one line:
    Code:
    addEHandler(window, 'load', doOnload);
    Make sure you include that file first before any other JS includes.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: trigger javascript onload from an include file?

    Thanks man. I will try it.

    And yes, the JS are in separated files.

    HoraShadow
    I do like the reward system. If you find that my post was useful, rate it.

Posting Permissions

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



Click Here to Expand Forum to Full Width