New to Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JSNewbie

    New to Javascript

    I am new to javascript. I used the code below in Netscape 7.0 and in
    IE 6.0. The Javascript portion does not render in Netscape , but it
    does show in IE. Can someone explain why? Any helpful insight would
    be appreciated.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    <html xmlins="http://www.w3.org/1999/xhtml">
    <head>
    <title>Java Script Test</title>
    </head>
    <body bgcolor="#FFFFF ">
    <h1> What is your problem
    </h1>
    <script language="javas cript"
    type="text javascript">
    <!-- Hide script from old browsers

    document.write( "<h1> Today is </h1>")

    // End hiding script from old broswers -->
    </script>
    </body>
    </html>

  • Evertjan.

    #2
    Re: New to Javascript

    JSNewbie wrote on 29 mrt 2005 in comp.lang.javas cript:
    [color=blue]
    > I am new to javascript. I used the code below in Netscape 7.0 and in
    > IE 6.0. The Javascript portion does not render in Netscape , but it
    > does show in IE. Can someone explain why? Any helpful insight would
    > be appreciated.
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    > <html xmlins="http://www.w3.org/1999/xhtml">
    > <head>
    > <title>Java Script Test</title>
    > </head>
    > <body bgcolor="#FFFFF ">[/color]

    Better [get ]use[d to] CSS
    White is default anyway
    [color=blue]
    > <h1> What is your problem
    > </h1>
    > <script language="javas cript"[/color]

    language="javas cript" is depriciated, don't use
    [color=blue]
    > type="text javascript">
    > <!-- Hide script from old browsers[/color]

    <!-- is depriciated for this use for more than 5 years, don't use
    [color=blue]
    >
    > document.write( "<h1> Today is </h1>")[/color]

    no problemo!!!
    [color=blue]
    >
    > // End hiding script from old broswers -->[/color]

    see above
    [color=blue]
    > </script>
    > </body>
    > </html>[/color]

    Probably javascript switched off in the N7 broswer(?)



    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)

    Comment

    • Ivo

      #3
      Re: New to Javascript

      "Evertjan." wrote[color=blue]
      > JSNewbie wrote[color=green]
      > > <body bgcolor="#FFFFF ">[/color]
      >
      > Better [get ]use[d to] CSS
      > White is default anyway[/color]

      Not true. I know a machine where the default is gray, and another where the
      default on white text on blue. So another tip: if specifying a
      backgroundcolou r, you should explicitly set the foreground too.
      [color=blue][color=green]
      > > <!-- Hide script from old browsers[/color]
      >
      > <!-- is depriciated for this use for more than 5 years, don't use[/color]

      That has been said before in this newsgroup, but I 'm wondering why even
      sites like Google and Altavista still cloak comment their scripts like this.

      --
      Ivo


      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: New to Javascript

        "Evertjan." <exjxw.hannivoo rt@interxnl.net > writes:
        [color=blue]
        > JSNewbie wrote on 29 mrt 2005 in comp.lang.javas cript:
        >[color=green]
        >> I am new to javascript. I used the code below in Netscape 7.0 and in
        >> IE 6.0. The Javascript portion does not render in Netscape , but it
        >> does show in IE.[/color][/color]
        [color=blue][color=green]
        >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
        >> <html xmlins="http://www.w3.org/1999/xhtml">[/color][/color]
        Should be:
        <html xmlns="...
        [color=blue][color=green]
        >> <head>
        >> <title>Java Script Test</title>
        >> </head>
        >> <body bgcolor="#FFFFF ">[/color]
        >
        > Better [get ]use[d to] CSS
        > White is default anyway[/color]

        Agree on using CSS. Using XHTML with old, deprecated presentational tags
        is mixing styles. It won't lead to anything good.

        White is not the default background (not even in IE). The default is
        the operating system's default window background, which on my computer
        is slightly yellow. If you mean white, do use it.

        However, what is written is not white. It needs another "F" to become
        "#FFFFFF".
        [color=blue][color=green]
        >> <h1> What is your problem
        >> </h1>
        >> <script language="javas cript"[/color]
        >
        > language="javas cript" is depriciated, don't use[/color]

        It's "deprecated ", but it means almost the same :)
        [color=blue][color=green]
        >> type="text javascript">[/color][/color]

        This should be
        type="text/javascript">
        I think this is what is causing your problem. So, in total:

        <script type="text/javascript">

        is the way to start a script tag.
        [color=blue][color=green]
        >> <!-- Hide script from old browsers[/color]
        >
        > <!-- is depriciated for this use for more than 5 years, don't use[/color]

        It's not deprecated as an HTML comment, but it is correct that it is
        not needed inside a script element. The "old browsers" that it is
        supposed to hide the script from were succeeded by the generation
        of browsers starting with Netscape 2, around 1996.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: New to Javascript

          "Ivo" <no@thank.you > writes:

          [not use "<!-- hide from old browsers"][color=blue]
          > That has been said before in this newsgroup, but I 'm wondering why even
          > sites like Google and Altavista still cloak comment their scripts like this.[/color]

          Because it's voodoo. You can add it, and it doesn't hurt you, so why
          change anything that once worked.

          The problem is that it can hurt you if you use XHTML. An XML processor
          is free to remove comments before processing the rest, inside any
          element, so it could remove your script contents.

          Browsers probably won't do that, but if you use XHTML, it should be
          because you expect to use other tools on it (browsers are fine with
          HTML, IE doesn't even treat XHTML as XML, but only as malformed HTML).

          Any browser that understands the script tag, even those that don't
          understand its contents, will not need "<!--". That's pretty much any
          browser since Netscape 2.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Evertjan.

            #6
            Re: New to Javascript

            Lasse Reichstein Nielsen wrote on 29 mrt 2005 in comp.lang.javas cript:
            [color=blue][color=green]
            >> language="javas cript" is depriciated, don't use[/color]
            >
            > It's "deprecated ", but it means almost the same :)
            >[/color]

            Your correction is apprecated, I pray, Lasse!

            ===========

            M-W:
            Main Entry: dep·re·cate
            Etymology: Latin deprecatus,
            past participle of deprecari to avert by prayer,
            from de- + precari to pray

            Main Entry: ap·pre·ci·ate
            Etymology: Late Latin appretiatus,
            past participle of appretiare,
            from Latin ad- + pretium price


            --
            Evertjan.
            The Netherlands.
            (Replace all crosses with dots in my emailaddress)

            Comment

            • John W. Kennedy

              #7
              Re: New to Javascript

              JSNewbie wrote:[color=blue]
              > I am new to javascript. I used the code below in Netscape 7.0 and in
              > IE 6.0. The Javascript portion does not render in Netscape , but it
              > does show in IE. Can someone explain why? Any helpful insight would
              > be appreciated.
              >
              > <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
              > <html xmlins="http://www.w3.org/1999/xhtml">
              > <head>
              > <title>Java Script Test</title>
              > </head>
              > <body bgcolor="#FFFFF ">
              > <h1> What is your problem
              > </h1>
              > <script language="javas cript"
              > type="text javascript">
              > <!-- Hide script from old browsers
              >
              > document.write( "<h1> Today is </h1>")
              >
              > // End hiding script from old broswers -->
              > </script>
              > </body>
              > </html>
              >[/color]

              The DOCTYPE is incomplete, and it should have "html" instead of "HTML".

              The namespace property is spelled "xmlns", not "xmlins".

              Forcing the body background color only is bad practice, because you
              don't know what the user's default are. Either set all the colors or
              leave them alone.

              The "language" property of the "script" element is obsolete.

              The MIME type for JavaScript is "text/javascript", not "text javascript".

              Using <!-- ... --> is obsolete.

              document.write does not work with XHTML (and isn't supposed to). Use the
              DOM model.

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
              "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
              <html xmlns="http://www.w3.org/1999/xhtml">
              <head>
              <title>Java Script Test</title>
              </head>
              <body>
              <h1> What is your problem</h1>
              <script type="text/javascript">
              var body = document.getEle mentsByTagName( "body")[0];
              var h1 = document.create Element("h1");
              h1.appendChild (document.creat eTextNode (" Today is "));
              body.appendChil d (h1);
              </script>
              </body>
              </html>
              --
              John W. Kennedy
              "Compact is becoming contract,
              Man only earns and pays."
              -- Charles Williams. "Bors to Elayne: On the King's Coins"

              Comment

              • Mick White

                #8
                Re: New to Javascript

                JSNewbie wrote:
                [color=blue]
                > I am new to javascript. I used the code below in Netscape 7.0 and in
                > IE 6.0. The Javascript portion does not render in Netscape , but it
                > does show in IE. Can someone explain why? Any helpful insight would
                > be appreciated.
                >
                > <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
                > <html xmlins="http://www.w3.org/1999/xhtml">
                > <head>
                > <title>Java Script Test</title>
                > </head>
                > <body bgcolor="#FFFFF ">[/color]

                No such colour...
                Mick

                [color=blue]
                > <h1> What is your problem
                > </h1>
                > <script language="javas cript"
                > type="text javascript">
                > <!-- Hide script from old browsers
                >
                > document.write( "<h1> Today is </h1>")
                >
                > // End hiding script from old broswers -->
                > </script>
                > </body>
                > </html>
                >[/color]

                Comment

                Working...