External JS file

Discussion in 'JavaScript' started by neweraprime, Jan 16, 2010.

  1. #1
    I call an external .js file into my HTML pages.Now i want to load a function (from that external file) when the body load.What should i do.

    Example:
    <body onload="what should i write here to load the function of external js file?">

    As i now the external js is call as:
    <script type="text/javascript" src="" ></script>

    or what other thing you suggest me?
    Regards
     
    neweraprime, Jan 16, 2010 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Just call the function like you would any other, using its name:
    
    <body onload="myFunction();">
    
    Code (markup):
    alternatively, you can add this event handler from the source of your script:
    
    function loadHandler() {
        //Do whatever you need to do here...
    }
    
    [B]window.onload = loadHandler;[/B]
    
    Code (markup):
     
    camjohnson95, Jan 16, 2010 IP