Trying to understand this code

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

    Trying to understand this code

    Here is the code I found:

    <script language="JavaS cript">
    <!--
    if (parent.frames. length > 0)
    {
    parent.location .href = location.href;
    }
    -->
    </script>

    What it looks like I'm seeing is a function that will automatically
    break the page out of any frameset it finds itself in. Am I right?

    Chad Lupkes
    chadlupkes@yaho o.com
  • Lasse Reichstein Nielsen

    #2
    Re: Trying to understand this code

    chadlupkes@yaho o.com (Chad Lupkes) writes:
    [color=blue]
    > Here is the code I found:
    >
    > <script language="JavaS cript">[/color]

    It's
    <script type="text/javascript">
    In HTML 4, the type attrbute is required.
    [color=blue]
    > <!--[/color]

    HTML comments are useless in Javascript.
    [color=blue]
    > if (parent.frames. length > 0)
    > {
    > parent.location .href = location.href;
    > }[/color]
    [color=blue]
    > What it looks like I'm seeing is a function that will automatically
    > break the page out of any frameset it finds itself in. Am I right?[/color]

    This code testes whether the parent window/frames has more than one
    frame inside it. If it does, this page is loaded into the parent.

    It will not break out of a parent frame with only one subframe. That
    is quite possible, if the parent includes this page in an iframe.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Tony Vasquez

      #3
      Re: Trying to understand this code


      "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
      news:u17pgvxq.f sf@hotpop.com.. .[color=blue]
      > chadlupkes@yaho o.com (Chad Lupkes) writes:
      >[color=green]
      > > Here is the code I found:
      > >
      > > <script language="JavaS cript">[/color]
      >
      > It's
      > <script type="text/javascript">
      > In HTML 4, the type attrbute is required.
      >[color=green]
      > > <!--[/color]
      >
      > HTML comments are useless in Javascript.[/color]

      Don't be such a prick, maybe he's trying to code for, or keep in practice
      for backward compatability with older browsers, or non-javascript enabled
      browsers. Don't act like you don't know what that comment mark is for.

      Tony Vasquez


      [color=blue]
      >[color=green]
      > > if (parent.frames. length > 0)
      > > {
      > > parent.location .href = location.href;
      > > }[/color]
      >[color=green]
      > > What it looks like I'm seeing is a function that will automatically
      > > break the page out of any frameset it finds itself in. Am I right?[/color]
      >
      > This code testes whether the parent window/frames has more than one
      > frame inside it. If it does, this page is loaded into the parent.
      >
      > It will not break out of a parent frame with only one subframe. That
      > is quite possible, if the parent includes this page in an iframe.
      >
      > /L
      > --
      > Lasse Reichstein Nielsen - lrn@hotpop.com
      > Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      > 'Faith without judgement merely degrades the spirit divine.'[/color]


      Comment

      • DU

        #4
        Re: Trying to understand this code

        Tony Vasquez wrote:

        [color=blue]
        >
        > Don't be such a prick, maybe he's trying to code for, or keep in practice
        > for backward compatability with older browsers, or non-javascript enabled
        > browsers. Don't act like you don't know what that comment mark is for.
        >
        > Tony Vasquez
        >[/color]

        It's amazing how fast people resort to abrasive remarks, name-calling or
        just plain agressive posts when a simple question done in a neutral
        manner was appropriate and would have done a whole difference.

        DU
        --
        Javascript and Browser bugs:

        - Resources, help and tips for Netscape 7.x users and Composer
        - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Trying to understand this code

          "Tony Vasquez" <condorschool@e arthlink.net> writes:
          [color=blue][color=green]
          > > HTML comments are useless in Javascript.[/color]
          >
          > Don't be such a prick, maybe he's trying to code for, or keep in practice
          > for backward compatability with older browsers, or non-javascript enabled
          > browsers. Don't act like you don't know what that comment mark is for.[/color]

          I can see I should have kept my usual wording, and not replaced
          "unneeded" with "useless".

          Still, it doesn't change that it is correct.

          The tradition of adding HTML comments was introduced with the first
          browser to understand the script tag, Netscape 2, to hide the scripts
          from Netscape 1 and other contemporal browsers.

          The browsers that need HTML comments to hide the contents of a script
          tag, are browsers that don't understand the script tag at all. The tag
          was included in HTML 3.2, which was made a recommendation in January
          1997, and was in use in browsers even before.

          The most recents such browser not understanding the scrip tag, that I
          am aware off, are Netscape 1, Internet Explorer 2, Lynx 2.4, and Opera
          2. These were succeeded by more modern browsers around 1996 (Opera not
          until 1997).

          Any slightly recent browser that doesn't support Javascript (like Lynx
          2.5 from May 1996) still understands the script tag, probably as part
          of HTML 3.2, and knows not to render its content.

          I know exactly what the HTML comment is for, and it is not needed for
          browsers created after 1996. If you can find just *one* version of IE2
          or NS1 in actualy use (and not just by weirdos like me who collects
          browsers), then I would accept that HTML comments in Javascript tags
          have a use.

          Until then, I stand by my opinion: HTML tags are of no use in
          Javascript.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Evertjan.

            #6
            Re: Trying to understand this code

            Lasse Reichstein Nielsen wrote on 07 sep 2003 in comp.lang.javas cript:[color=blue]
            > Until then, I stand by my opinion: HTML tags are of no use in
            > Javascript.[/color]

            Hear, hear !

            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            • Dr John Stockton

              #7
              Re: Trying to understand this code

              JRS: In article <4qzoc1eu.fsf@h otpop.com>, seen in
              news:comp.lang. javascript, Lasse Reichstein Nielsen <lrn@hotpop.com >
              posted at Sun, 7 Sep 2003 12:56:25 :-
              [color=blue][color=green][color=darkred]
              >> > HTML comments are useless in Javascript.[/color][/color][/color]
              [color=blue]
              >I can see I should have kept my usual wording, and not replaced
              >"unneeded" with "useless".
              >
              >Still, it doesn't change that it is correct.[/color]

              Actually it is not quite correct.

              It is, I think, true to say that no recent Web browser needs those
              comments, and perhaps also that the number of older browsers still in
              use is negligible (remember the possibility of old systems in third-
              world locations, however).

              It may well be equally true to say the same about Javascript executed in
              Web servers, and elsewhere.

              It may well be true to say the same about all currently-available Web-
              page validators, with a similar caveat about old versions of
              downloadable ones.

              But there is at least one publicly-available tool which reads Web page
              masters and which under at least some circumstances benefits from the
              presence of <!-- and --> around script.

              There is a somewhat analogous situation with Web page masters containing
              VBscript. VBScript comment by definition is introduced by ', equivalent
              to javascript // - however, my latest copy of W3's TIDY does not like
              this, but is happy with '' - IIRC.

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
              Web <URL:http://www.merlyn.demo n.co.uk/> - FAQqish topics, acronyms & links.
              PAS EXE TXT ZIP via <URL:http://www.merlyn.demo n.co.uk/programs/00index.htm>.
              Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)

              Comment

              • Jim Ley

                #8
                Re: Trying to understand this code

                On Sun, 7 Sep 2003 20:01:56 +0100, Dr John Stockton
                <spam@merlyn.de mon.co.uk> wrote:
                [color=blue]
                >It is, I think, true to say that no recent Web browser needs those
                >comments, and perhaps also that the number of older browsers still in
                >use is negligible (remember the possibility of old systems in third-
                >world locations, however).[/color]

                In the 3rd world those browsers are even less likely to be used as at
                least one of them didn't know HTTP 1.1 and outside the 1st English
                speaking world, there's an even larger proportion of virtual hosts
                than non (since they don't have as many IP addresses as the "west")
                [color=blue]
                >But there is at least one publicly-available tool which reads Web page
                >masters and which under at least some circumstances benefits from the
                >presence of <!-- and --> around script.[/color]

                Yes, but seen as people are authoring XHTML, this will cause problems
                since in XHTML such comments will mean that the script is _not
                executed_ So on the balance of properties in the real world today,
                I'd say going with the so-called future, is a better bet than the
                remote past on browsers which are unusable on the web today.

                Jim.
                --
                comp.lang.javas cript FAQ - http://jibbering.com/faq/

                Comment

                • Lasse Reichstein Nielsen

                  #9
                  Re: Trying to understand this code

                  Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
                  [color=blue]
                  > But there is at least one publicly-available tool which reads Web page
                  > masters and which under at least some circumstances benefits from the
                  > presence of <!-- and --> around script.[/color]

                  Don't leave us hanging in suspense! What is it? :)

                  /L
                  --
                  Lasse Reichstein Nielsen - lrn@hotpop.com
                  Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
                  'Faith without judgement merely degrades the spirit divine.'

                  Comment

                  • Dr John Stockton

                    #10
                    Re: Trying to understand this code

                    JRS: In article <vfs4uziz.fsf@h otpop.com>, seen in
                    news:comp.lang. javascript, Lasse Reichstein Nielsen <lrn@hotpop.com >
                    posted at Sun, 7 Sep 2003 22:14:28 :-[color=blue]
                    >Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
                    >[color=green]
                    >> But there is at least one publicly-available tool which reads Web page
                    >> masters and which under at least some circumstances benefits from the
                    >> presence of <!-- and --> around script.[/color]
                    >
                    >Don't leave us hanging in suspense! What is it? :)[/color]

                    A clue was in the third line of the signature (repeated).

                    CHEKLINK, running on a PC in 16- and 32- bit versions, will check the
                    relative links on [the master copy of] a Web site, recursively, to see
                    whether the file and/or anchor cited by each link actually exists in the
                    master. It checks a few other things /en passant/.

                    Since its high-speed scanner was written to ignore all bar a few HTML
                    elements, but naturally to recognise <!-- --> (acknowledged : perhaps
                    that is not the full generality of HTML comment; but it is all that I've
                    ever seen used), it is entirely ignorant of the contents of
                    traditionally-protected script (unless out of sheer folly a string
                    literal contains -->). But, without the protection, it may run out of
                    buffer length (and thus abort) while scanning script.

                    I think also that one version of W3's TIDY (HTML checker) could be led
                    astray by <a in unprotected script, where a is any letter and there is
                    no suitable matching > - I spent a while changing <a to < a to fix that,
                    after removing <!-- & -->.

                    But an advantage of removal is that CHEKLINX will then check the link in
                    document.write( '<a href="filename. htm#anchor">GO</a>'). I do not know
                    how many of such I had that were satisfactory, but it did find one that
                    was not; the destination had moved.


                    Those show that the removal of the deprecated <!-- & --> is not
                    necessarily consequence-free.

                    --
                    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                    Web <URL:http://www.merlyn.demo n.co.uk/> - FAQqish topics, acronyms & links.
                    PAS EXE TXT ZIP via <URL:http://www.merlyn.demo n.co.uk/programs/00index.htm>.
                    Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)

                    Comment

                    Working...