How to outsource Javascript code from html code ?

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

    #16
    Re: How to outsource Javascript code from html code ?

    In article <y7sAS9EsND9$Ew 4C@merlyn.demon .co.uk>, Dr John Stockton
    <spam@merlyn.de mon.co.uk> writes:
    [color=blue][color=green]
    >>1) The "html comments" are not needed in any browser less than 10 years old.
    >>2) They are not "html comments", they are part of the script block and as[/color]
    >such[color=green]
    >>are part of the script.[/color]
    >
    >A) They may be useful if the page is being processed by software other
    >than a browser.[/color]

    Agreed that they may be useful in software other than a browser. But that still
    doesn't change the content type of a script block.
    [color=blue]
    >B) They are HTML comments, since they are for use when the script tag is
    >not recognised.[/color]



    Leads to a discussion not long ago (Nov 9, 2003) about whether they are HTML
    comments or part of the script block. To quote Jim Ley:

    <quote>
    [color=blue][color=green]
    >> That's a javascript comment, not an HTML one, and it can cause no harm
    >> (in XHTML things are different of course)[/color]
    >
    >The string "<!--" begins an HTML comment.[/color]

    The content model of SCRIPT is CDATA - you're not allowed comments
    inside it, therefore that must be part of the script, and passed to
    the script engine. Certainly it's not part of ECMAScript, but that is
    not an HTML comment - they're not legal inside SCRIPT blocks (this is
    the change with XHTML of course where the content model of script
    changed to PCDATA which allows comments.)

    It's either a javascript comment, or something that the javascript
    engine accepts as if it was a comment - it's passed as is via the HTML
    parser.

    Jim.
    </quote>

    So, they are part of the script block, and not an HTML comment.
    --
    Randy

    Comment

    • Lasse Reichstein Nielsen

      #17
      Re: How to outsource Javascript code from html code ?

      hikksnotathome@ aol.com (HikksNotAtHome ) writes:
      [color=blue]
      > So, they are part of the script block, and not an HTML comment.[/color]

      The point that Dr. Stockton made, and that I wish I had made to Jim
      Ley then, is that whether it is part of the script block or an HTML
      comment depends on 1) the version of HTML and 2) the browser.

      The reason to put the <!-- there at all, is that *some* browsers treat
      it as the start of an HTML comment. Other browsers treat it as part
      of the script block (and actually break ECMAScript compliance to do it:
      var x = 2;
      if (1 <!-- x
      ) { alert("foul");}
      is a valid syntactically correct ECMAScript program that should not
      call the function "alert", but does in the browsers I checked - IE 6,
      Opera 7 and Moz FB).

      But the reason to write the <!-- at all, is to have it interpreted as
      an HTML comment. So, at least partially, it *is* an HTML comment.

      /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

      • HikksNotAtHome

        #18
        Re: How to outsource Javascript code from html code ?

        In article <r7yjrz0b.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
        writes:
        [color=blue]
        >But the reason to write the <!-- at all, is to have it interpreted as
        >an HTML comment. So, at least partially, it *is* an HTML comment.[/color]

        No, its part of a script block that is interpreted as an HTML comment not a
        true HTML comment.

        All of it is purely semantical though until you escape the HTML world.
        --
        Randy

        Comment

        • Lasse Reichstein Nielsen

          #19
          Re: How to outsource Javascript code from html code ?

          hikksnotathome@ aol.com (HikksNotAtHome ) writes:
          [color=blue]
          > No, its part of a script block that is interpreted as an HTML comment not a
          > true HTML comment.[/color]

          To Netscape 1, it is an HTML comment, because that browser doesn't
          know what a script block is. As a well behaved HTML client, it ignores
          unknown tags and finds the HTML comment inside.

          The reason to add the <!-- and //--> is to make Netscape 1 and
          contemporary browsers treat it as an HTML comment. Later browsers
          gracefully ignores <!-- and --> inside script blocks, since they are
          not placed there for these, smarter, browsers. It is added for one
          purpose only: To be used as an HTML comment.
          [color=blue]
          > All of it is purely semantical though until you escape the HTML world.[/color]

          To where? :)

          The problem might be that it is the difference between HTML syntax and
          actual browser semantics.

          /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

          Working...