basics of script tag and attributes, where to put

Discussion in 'Javascript' started by awebguynow, Sep 6, 2006.

  1. awebguynow

    awebguynow Guest

    I've always thought a script tag to ref and ext JS file, should be
    structured, like so
    <script type="text/javascript" src="foo.js"></script>

    I've noticed in some of the Venkman tutorials only use the "src"
    attribute.
    What is the best coding style ?

    Also, I've done some event-driven JS programming (onEvent), but I've
    also seen examples of <script> placed anywhere in an html file. I
    think the whole html file is sent to the browswer, and JS called where
    ever it is placed, but I am having calling a function in an external
    file.

    I plan on using Venkman more to debug, since I have no desire to get
    MS's VS or MS Script Editor which comes with Office XP.
     
    awebguynow, Sep 6, 2006
    #1
    1. Advertising

  2. awebguynow

    Patient Guy Guest

    "awebguynow" <> wrote in comp.lang.javascript:

    > I've always thought a script tag to ref and ext JS file, should be
    > structured, like so
    > <script type="text/javascript" src="foo.js"></script>


    This is technically an HTML question and not Java/ECMAscript. I would
    advise you to follow what you consider the most authoritative standard or
    specification you have. (Note that the W3 Consortium does not refer to
    their "standards" or "specifications" as such, but more modestly refers to
    them as "recommendations.")

    When deciding who is authoritative in the event of a dispute, you might
    consider who first originated the concepts involved in principle. But in
    practice, reality shows that you will also make decisions based on the
    usage of consensus.

    > I've noticed in some of the Venkman tutorials only use the "src"
    > attribute.
    > What is the best coding style ?


    The developers of Venkman would probably not be considered even remotely
    authoritative when it comes to writing HTML properly, and they would
    probably not claim to be authoritative as well.

    You could consider them authoritative when it comes to writing Javascript
    debuggers however.

    > Also, I've done some event-driven JS programming (onEvent), but I've
    > also seen examples of <script> placed anywhere in an html file. I
    > think the whole html file is sent to the browswer, and JS called where
    > ever it is placed, but I am having calling a function in an external
    > file.


    Script elements can be placed legally within the head and body of the HTML
    document. The only thing that you have to keep in mind is that everything
    is defined and objectified---the document content, the scripts---in the
    order in which it is read, and reading is synchronous generally.

    Thus if you make reference to (call, make use of) a variable or function
    before the actual definition of that variable or function, expect an error
    or exception. Note that variables or functions coded within the scope of
    a function is not referencing or calling or making use of those variables
    or functions when the function containing them is being defined.

    When external JS file are "included" within an HTML document, it is
    equivalent to inserting all their code at that place in the document where
    the script elements are placed. Make sure they are relatively error-free
    before moving their code to an external JS file: a single coding (not
    runtime) error in some (maybe all) browsers effectively cancels all
    variables and functions defined in that file as being part of the global
    scope.


    > I plan on using Venkman more to debug, since I have no desire to get
    > MS's VS or MS Script Editor which comes with Office XP.


    You should reconsider this if you intend that your scripts get widespread
    use. The (horrible?) fact of life is that Internet Explorer is still the
    giant in browser usage, and it differs from Mozilla/Firefox/real
    Javascript browsers in only a small number of ways.

    I do the heavy-lifting (initial code development) in Firefox with Venkman
    and the Error2 console, as well as those extensions that display element
    information right in the rendered page.

    And then I set about to see how it runs in MSIE with the Script Debugger
    handy and a battery of information about how to use ActiveX objects, if
    needed.
     
    Patient Guy, Sep 6, 2006
    #2
    1. Advertising

  3. awebguynow

    Randy Webb Guest

    awebguynow said the following on 9/6/2006 1:35 PM:
    > I've always thought a script tag to ref and ext JS file, should be
    > structured, like so
    > <script type="text/javascript" src="foo.js"></script>


    According to W3C and the HTML Specs, that is what is expected from the
    Validator.

    > I've noticed in some of the Venkman tutorials only use the "src"
    > attribute.
    > What is the best coding style ?


    Personal preference. I have yet to see (with one exception) where
    <script src="someFile.js"></script> didn't work properly. That one
    exception is in IE and that is only if you have a VBScript script
    element in the page first.

    As for the type attribute itself, it is ironic that the W3C validator
    insists upon a type attribute yet there are no official MIME Types for
    script elements.

    > I plan on using Venkman more to debug, since I have no desire to get
    > MS's VS or MS Script Editor which comes with Office XP.


    You can totally debug scripts without any debugger other than the
    browsers themselves. And, Firefox doesn't always give a true error
    message. See the thread from just today entitled "inserting scripts into
    the DOM" with respect to the error messages given by IE, Opera and Firefox.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Sep 6, 2006
    #3
  4. Randy Webb wrote:

    [snip]

    > As for the type attribute itself, it is ironic that the W3C validator
    > insists upon a type attribute yet there are no official MIME Types
    > for script elements.


    Yes there are, though there wasn't at the time the Recommendation was
    written.

    [snip]

    Mike
     
    Michael Winter, Sep 6, 2006
    #4
  5. Patient Guy wrote:

    > "awebguynow" <> wrote in comp.lang.javascript:


    [snip]

    >> I plan on using Venkman more to debug, since I have no desire to
    >> get MS's VS or MS Script Editor which comes with Office XP.

    >
    > You should reconsider this if you intend that your scripts get
    > widespread use.


    Why? The OP wrote "more to debug", not "do all of my testing". It seems
    that he intends to do almost precisely what you described for yourself:
    primary development with a decent debugging tool, then testing
    afterwards in IE (having hopefully eliminated all bugs, anyway).

    [snip]

    Mike
     
    Michael Winter, Sep 6, 2006
    #5
  6. awebguynow

    Patient Guy Guest

    Michael Winter <> wrote in comp.lang.javascript:

    > Patient Guy wrote:
    >
    >> "awebguynow" <> wrote in comp.lang.javascript:

    >
    > [snip]
    >
    >>> I plan on using Venkman more to debug, since I have no desire to
    >>> get MS's VS or MS Script Editor which comes with Office XP.

    >>
    >> You should reconsider this if you intend that your scripts get
    >> widespread use.

    >
    > Why? The OP wrote "more to debug", not "do all of my testing". It seems
    > that he intends to do almost precisely what you described for yourself:
    > primary development with a decent debugging tool, then testing
    > afterwards in IE (having hopefully eliminated all bugs, anyway).


    My reading of his statement is that he does not plan to use a development
    environment provided by MS, typically to debug script execution in IE. He
    did not state whether he wanted his scripts to run in IE or whether he
    cared if they did or not. If you say there is an ambiguity in his
    comments, I can agree.

    At any rate, he might quickly learn the necessity of having to use a MS-
    provided development environment if he also wanted those scripts to run in
    IE.
     
    Patient Guy, Sep 7, 2006
    #6
  7. awebguynow

    awebguynow Guest

    I've had trouble putting <script> tag in html near the bottom of a
    page, even though I've used this placement before, as instructed, with
    an external script I downloaded.

    When placing the script tag in this position, I get the popup showing
    IE error:
    "cannot open the Internet site ..."
     
    awebguynow, Sep 19, 2006
    #7
  8. awebguynow

    Andy Dingley Guest

    Randy Webb wrote:
    > As for the type attribute itself, it is ironic that the W3C validator
    > insists upon a type attribute yet there are no official MIME Types for
    > script elements.


    Does the W3C validator (a HTML validator) require a particular value /
    values for the type attribute, or merely that it exists ?

    It's only valid HTML if the type attribute is used, but HTML doesn't
    specify what it ought to be. After all, even VBScript is valid HTML.
    The choice of a correct value for type is one question, the choice of a
    widely-supported and web-appropriate one is another, but neither of
    these are questions about HTML validity.
     
    Andy Dingley, Sep 19, 2006
    #8
  9. awebguynow

    awebguynow Guest

    IE error: "cannot open the Internet site ..." .
    only occurs when the <script> tag is inside a div..
     
    awebguynow, Sep 21, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RC
    Replies:
    2
    Views:
    446
    Malte
    May 10, 2005
  2. shruds
    Replies:
    1
    Views:
    881
    John C. Bollinger
    Jan 27, 2006
  3. RC
    Replies:
    2
    Views:
    668
  4. Eqbal Z
    Replies:
    6
    Views:
    195
    Eqbal Z
    Aug 27, 2003
  5. John MacIntyre
    Replies:
    1
    Views:
    196
    Lasse Reichstein Nielsen
    Sep 29, 2003
Loading...

Share This Page