SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why does some javascript have to be in the head tag and some don't? I want to be able a pop up with a cookie without having to have code in the head tag AND a call in the body tag (to pop up onload). Is there a way where I can stick everything in the body tag?

  2. #2
    Irritability Defined
    Join Date
    Jul 2000
    Location
    80,000 feet below the surface
    Posts
    1,442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I am aware there really is little difference in putting JavaScript code in either the head or body sections of the HTML page. However, most JScript programmers seem to prefer putting it in the <head> section so that the <body> section is less cluttered, as well as allowing the JavaScript functions to be parsed and loaded first then cached to the user's browser.

    Of course, if you wanted a JavaScript to load at the very end you'd put it just above the </body> tag...

    Cookies *might* be a completely different story however..
    My 2 Cents (or is that 2.2 Cents including GST?)

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by BC
    As far as I am aware there really is little difference in putting JavaScript code in either the head or body sections of the HTML page. However, most JScript programmers seem to prefer putting it in the &lt;head&gt; section so that the &lt;body&gt; section is less cluttered, as well as allowing the JavaScript functions to be parsed and loaded first then cached to the user's browser.

    Of course, if you wanted a JavaScript to load at the very end you'd put it just above the &lt;/body&gt; tag...

    Cookies *might* be a completely different story however..
    Did you mean JavaScript when you said JScript? I think they're actually different things. How's that for confusing?

    Yes, personally I have no problem print out a variable anywhere on a webpage for the most part: <script language="JavaScript">document.write(varName);</script> - simple as heck.

    However, to, for example, create a JavaScript that always displays the current date, there are maybe 10 lines or so of code involved - makes more sense to keep that up in the HEAD tag and not get it in the way of everything else, when I can hold the final date info in a variable and just print it out anywhere else as you can see above.

  4. #4
    Irritability Defined
    Join Date
    Jul 2000
    Location
    80,000 feet below the surface
    Posts
    1,442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by TWTCommish
    Did you mean JavaScript when you said JScript? I think they're actually different things. How's that for confusing?
    [/B]
    Shhhhhhhhhh stop confusing him! Yes, I meant the exact same thing (not Microsoft's other version of JScript)

    No hang on, errrr, was that me.....
    My 2 Cents (or is that 2.2 Cents including GST?)


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
  •