javascript

Discussion in 'HTML' started by Rafal 'Raf256' Maj, Dec 2, 2003.

  1. What is the correct way of put javascript code in XHTML 1 document, in

    1) head

    2) body



    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~l-.~~~~~~~~~~~~~~~~~~~
    GG-1175498 ____| ]____,
    Rafal 'Raf256' Maj X-( * )
    Rafal(at)Raf256(dot)com ,"----------"
     
    Rafal 'Raf256' Maj, Dec 2, 2003
    #1
    1. Advertising

  2. Rafal 'Raf256' Maj wrote:
    > What is the correct way of put javascript code in XHTML 1 document, in
    >
    > 1) head
    >
    > 2) body


    linked file - from the head

    --
    William Tasso - http://WilliamTasso.com
     
    William Tasso, Dec 2, 2003
    #2
    1. Advertising

  3. Rafal 'Raf256' Maj wrote:
    > What is the correct way of put javascript code in XHTML 1 document, in
    >
    > 1) head
    >
    > 2) body


    Its valid in either, it usually only makes sense if you stick it in the head
    (becuase it isn't content unless you document.write() and document.write
    isn't generally a good idea in XHTML).

    --
    David Dorward <http://dorward.me.uk/>
     
    David Dorward, Dec 2, 2003
    #3
  4. Rafal 'Raf256' Maj

    Louis Somers Guest

    "Rafal 'Raf256' Maj" <> wrote in
    news:Xns9445DB216D5C9raf256com@213.180.128.20:

    >
    > What is the correct way of put javascript code in XHTML 1 document, in
    >
    > 1) head
    >
    > 2) body
    >


    I prefer the head because non-supporting browsers are less likely to print
    the script on the users screen. If you choose to put it in the body
    remember to use the <!-- comments, so non-supporting browsers won't
    display the code.

    --
    News Updater, No scripts, No Database
    http://www.xmlssoftware.com/NUpdater
     
    Louis Somers, Dec 2, 2003
    #4
  5. Louis Somers wrote:

    > I prefer the head because non-supporting browsers are less likely to print
    > the script on the users screen. If you choose to put it in the body
    > remember to use the <!-- comments, so non-supporting browsers won't
    > display the code.


    You can't use <!-- to hide JavaScript in XHTML: the comment marks will
    *really* make it into a comment and it will be ignored by conforming
    browsers.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
     
    Toby A Inkster, Dec 2, 2003
    #5

  6. news:Xns9445DE87820630546179nospamstudent@194.109.133.29

    > I prefer the head because non-supporting browsers are less likely to
    > print the script on the users screen. If you choose to put it in the
    > body remember to use the <!-- comments, so non-supporting browsers
    > won't display the code.


    Thanks, and - how exacly looks sample JS code in XHTML?

    <!DOCTYPE ...>
    <html>
    <head> ...
    <script language="javascript 1.1">

    here_some_js_code

    </script>
    </head>
    <body>
    ....


    ?

    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~l-.~~~~~~~~~~~~~~~~~~~
    GG-1175498 ____| ]____,
    Rafal 'Raf256' Maj X-( * )
    Rafal(at)Raf256(dot)com ,"----------"
     
    Rafal 'Raf256' Maj, Dec 2, 2003
    #6
  7. Rafal 'Raf256' Maj

    m Guest

    Rafal 'Raf256' Maj wrote:

    >
    > news:Xns9445DE87820630546179nospamstudent@194.109.133.29
    >
    >> I prefer the head because non-supporting browsers are less likely to
    >> print the script on the users screen. If you choose to put it in the
    >> body remember to use the <!-- comments, so non-supporting browsers
    >> won't display the code.

    >
    > Thanks, and - how exacly looks sample JS code in XHTML?
    >
    > <!DOCTYPE ...>
    > <html>
    > <head> ...
    > <script language="javascript 1.1">
    >
    > here_some_js_code
    >
    > </script>
    > </head>
    > <body>
    > ...
    >
    >
    > ?
    >

    No, like:
    <script language="JavaScript">
    <![CDATA[
    .......................your javascript code.............
    ]]>
    </script

    The CDATA section prevents your javascript from being
    interpreted as part of an XML document proper.

    Just do yourself a favor: link to a separate
    file and avoid all this.

    I don't know why I can never convince beginners
    that separate files will save you work instead
    of costing; but I theorize that it has something
    to do with being awkward on an editor. Put your
    CSS and Javascript in separate files _now_-- you'll be
    glad you did as your site grows.
    --
    Cheers, m -- mbstevens.com
     
    m, Dec 2, 2003
    #7
  8. Rafal 'Raf256' Maj

    rf Guest

    "Louis Somers" <> wrote in message
    news:Xns9445DE87820630546179nospamstudent@194.109.133.29...
    > "Rafal 'Raf256' Maj" <> wrote in
    > news:Xns9445DB216D5C9raf256com@213.180.128.20:
    >
    > >
    > > What is the correct way of put javascript code in XHTML 1 document, in
    > >
    > > 1) head
    > >
    > > 2) body
    > >

    >
    > I prefer the head because non-supporting browsers are less likely to print
    > the script on the users screen. If you choose to put it in the body
    > remember to use the <!-- comments, so non-supporting browsers won't
    > display the code.


    The only non-javascript that does not simply ignore the entire <script>
    element (as it should) was a IIRC certain release of Netscape 3 which only
    lasted for a few months anyway. The use of HTML comments inside a <script>
    element has been cargo cult from then on :)

    Cheers
    Richard.
     
    rf, Dec 2, 2003
    #8
  9. Rafal 'Raf256' Maj

    Steve Pugh Guest

    "Rafal 'Raf256' Maj" <> wrote:

    >
    >news:Xns9445DE87820630546179nospamstudent@194.109.133.29
    >
    >> I prefer the head because non-supporting browsers are less likely to
    >> print the script on the users screen. If you choose to put it in the
    >> body remember to use the <!-- comments, so non-supporting browsers
    >> won't display the code.


    Yeah, there are so many Netscape 1 browsers still in use...

    These days even browsers that con't support JavaScript (or any other
    scripting language) know not to display the contents of a <script>
    element.

    >Thanks, and - how exacly looks sample JS code in XHTML?
    >
    ><script language="javascript 1.1">
    >
    > here_some_js_code
    >
    ></script>


    In theory the combination needed to satisfy both XHTML rules and older
    tag soup browsers is

    <script type="text/javascript">
    <!-- --> <![CDATA[ /> <!--
    here_some_js_code
    // --> <! ]]>
    </script>

    In practice putting it in an external .js file is a much better idea.

    Steve

    --
    "My theories appal you, my heresies outrage you,
    I never answer letters and you don't like my tie." - The Doctor

    Steve Pugh <> <http://steve.pugh.net/>
     
    Steve Pugh, Dec 2, 2003
    #9
  10. rf wrote:

    > The only non-javascript that does not simply ignore the entire <script>
    > element (as it should) was a IIRC certain release of Netscape 3 which only
    > lasted for a few months anyway. The use of HTML comments inside a <script>
    > element has been cargo cult from then on :)


    This is the case for <script> elements in the document's <head>, but for
    <script> elements in the <body>, a lot of older browsers will display the
    script contents.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
     
    Toby A Inkster, Dec 3, 2003
    #10
  11. While the city slept, Rafal 'Raf256' Maj <> feverishly typed:

    > What is the correct way of put javascript code in XHTML 1 document, in
    >
    > 1) head
    >
    > 2) body


    Traditionally, javascript has been placed in the head so that any functions
    called from the body will have been loaded in. It also makes sense (as
    suggested by other posters) to link to a javascript file - especially if
    your script is being used on more than one page - as changes to the script
    only have to be made on one file.

    Cheers,
    Nige

    --
    Nigel Moss.

    Email address is not valid. . Take the dog out!
    http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
    In the land of the blind, the one-eyed man is very, very busy!
     
    nice.guy.nige, Dec 3, 2003
    #11
    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. mcdeveloper
    Replies:
    1
    Views:
    4,225
    mcdeveloper
    Jun 13, 2006
  2. CRON
    Replies:
    24
    Views:
    201,661
    Adrienne Boswell
    Jun 20, 2006
  3. Mark Rae

    JavaScript or not JavaScript

    Mark Rae, Sep 5, 2006, in forum: ASP .Net
    Replies:
    36
    Views:
    1,111
    Paul Sture
    Sep 9, 2006
  4. Nathan Sokalski
    Replies:
    4
    Views:
    598
    PJ on Development
    Nov 8, 2007
  5. Lisa Calla
    Replies:
    0
    Views:
    288
    Lisa Calla
    Nov 9, 2004
Loading...

Share This Page