SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Tacoma, WA
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    External Scripts & Calling Functions in Same Include

    I have always been taught that this will not work

    Code:
    <script type="text/javascript" src="js/my_functions.js">
       //call to function from the file my_functions.js
       some_function();
    </script>
    But just recently I was reading on a blog post and I saw them do this so now I'm confused here. What has been your experience with this. Last time I tried it out it didn't work. Maybe I should relook at this.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    javascript tags

    Interesting question. I've always done it
    HTML Code:
    <script type="text/javascript" src="js/my_functions.js">
    </script>
    <script type="text/javascript">
       //call to function from the file my_functions.js
       some_function();
    </script>
    with no problems so I've never thought to "short cut" by leaving out the "extra" script tags.

  3. #3
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There should be nothing wrong with that.

    Edit: Sorry, thought you had 2 seperate script tags. Not sure about yours.
    Last edited by SoulScratch; Feb 27, 2008 at 15:50.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    If a browser is using the script element contents when the src attribute is supplied, then they are doing it wrong.

    Here is what the W3C specs have to say.

    If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.
    http://www.w3.org/TR/html401/interac....html#h-18.2.1
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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