Riddle me this javascript please.

Discussion in 'HTML' started by Big Bill, Oct 6, 2004.

  1. Big Bill

    Big Bill Guest

    This worksa as it should;

    <SCRIPT language=javascript>if (self != top) {top.location.href =
    self.location.href}</SCRIPT>

    but this won't

    <SCRIPT language="javascript" type="text/javascript"><!-- if (self !=
    top) {top.location.href = self.location.href} --></SCRIPT>

    How come? Any ideas?

    BB
     
    Big Bill, Oct 6, 2004
    #1
    1. Advertising

  2. Big Bill wrote:
    > This worksa as it should;
    >
    > <SCRIPT language=javascript>if (self != top) {top.location.href =
    > self.location.href}</SCRIPT>
    >
    > but this won't
    >
    > <SCRIPT language="javascript" type="text/javascript"><!-- if (self !=
    > top) {top.location.href = self.location.href} --></SCRIPT>
    >
    > How come? Any ideas?
    >
    > BB


    maybe the dash-dash-gt needs a slash-slash before it?
     
    Disco Octopus, Oct 6, 2004
    #2
    1. Advertising

  3. Big Bill

    Big Bill Guest

    On Tue, 05 Oct 2004 23:45:08 GMT, "Disco Octopus"
    <> wrote:

    >Big Bill wrote:
    >> This worksa as it should;
    >>
    >> <SCRIPT language=javascript>if (self != top) {top.location.href =
    >> self.location.href}</SCRIPT>
    >>
    >> but this won't
    >>
    >> <SCRIPT language="javascript" type="text/javascript"><!-- if (self !=
    >> top) {top.location.href = self.location.href} --></SCRIPT>
    >>
    >> How come? Any ideas?
    >>
    >> BB

    >
    >maybe the dash-dash-gt needs a slash-slash before it?


    I forgot that in the above instance but, ahem, imagine that's there
    and it still doesn't work. I let Tidy loose on it and it did indeed
    bung those slashes in, I just forgot about them preparing the above
    example. <lisa simpson>tee-hee......</lisa simpson>

    BB
     
    Big Bill, Oct 6, 2004
    #3
  4. Big Bill

    Steve Pugh Guest

    On Tue, 05 Oct 2004 23:18:01 GMT, Big Bill <>
    wrote:

    >This worksa as it should;
    >
    ><SCRIPT language=javascript>if (self != top) {top.location.href =
    >self.location.href}</SCRIPT>
    >
    >but this won't
    >
    ><SCRIPT language="javascript" type="text/javascript"><!-- if (self !=
    >top) {top.location.href = self.location.href} --></SCRIPT>
    >
    >How come? Any ideas?


    The JavaScript parser treats <!-- as a JavaScript comment. It has too
    otherwise the cargo cult nonsense of putting <!-- at the start of
    script blocks would cause an error. So you've commented out your
    entire script.
    So either (a) use the first version or (b) put a line break between
    your cargo cult nonsense and your actual script.

    Steve
     
    Steve Pugh, Oct 6, 2004
    #4
  5. Big Bill

    SpaceGirl Guest

    Big Bill wrote:
    > This worksa as it should;
    >
    > <SCRIPT language=javascript>if (self != top) {top.location.href =
    > self.location.href}</SCRIPT>
    >
    > but this won't
    >
    > <SCRIPT language="javascript" type="text/javascript"><!-- if (self !=
    > top) {top.location.href = self.location.href} --></SCRIPT>
    >
    > How come? Any ideas?
    >
    > BB
    >


    Your script tag is wrong anyway

    <script type="text/javascript"> is all you need. Use MIME, you dont
    need to specify a language. Also, if you're writing XHTML, the <script>
    tag must be lowercase.

    ....others have answered your actual fault!

    --


    x theSpaceGirl (miranda)

    # lead designer @ http://www.dhnewmedia.com #
    # remove NO SPAM to email, or use form on website #
     
    SpaceGirl, Oct 6, 2004
    #5
  6. Big Bill

    Big Bill Guest

    On Wed, 06 Oct 2004 07:31:08 +0100, Steve Pugh <> wrote:

    >On Tue, 05 Oct 2004 23:18:01 GMT, Big Bill <>
    >wrote:
    >
    >>This worksa as it should;
    >>
    >><SCRIPT language=javascript>if (self != top) {top.location.href =
    >>self.location.href}</SCRIPT>
    >>
    >>but this won't
    >>
    >><SCRIPT language="javascript" type="text/javascript"><!-- if (self !=
    >>top) {top.location.href = self.location.href} --></SCRIPT>
    >>
    >>How come? Any ideas?

    >
    >The JavaScript parser treats <!-- as a JavaScript comment. It has too
    >otherwise the cargo cult nonsense of putting <!-- at the start of
    >script blocks would cause an error. So you've commented out your
    >entire script.
    >So either (a) use the first version or (b) put a line break between
    >your cargo cult nonsense and your actual script.
    >
    > Steve


    What about the hide scripts from older browsers thing? I thought that
    was the reason for the comment tags. This isn't my script, I hasten to
    add, I know very little of javascript. Like you couldn't tell.

    BB
     
    Big Bill, Oct 6, 2004
    #6
  7. Big Bill

    Big Bill Guest

    On Wed, 06 Oct 2004 09:22:40 +0100, SpaceGirl
    <> wrote:

    >Big Bill wrote:
    >> This worksa as it should;
    >>
    >> <SCRIPT language=javascript>if (self != top) {top.location.href =
    >> self.location.href}</SCRIPT>
    >>
    >> but this won't
    >>
    >> <SCRIPT language="javascript" type="text/javascript"><!-- if (self !=
    >> top) {top.location.href = self.location.href} --></SCRIPT>
    >>
    >> How come? Any ideas?
    >>
    >> BB
    >>

    >
    >Your script tag is wrong anyway
    >
    ><script type="text/javascript"> is all you need. Use MIME, you dont
    >need to specify a language. Also, if you're writing XHTML, the <script>
    >tag must be lowercase.


    Well, again, the language bit is for ye olde worlde browsers. It was
    all that was there before. I added the text/javascript bit. Even I
    know to do that. Small mercies etc. And I knew the XHTML bit too, just
    overlooked it in this example, sorry.

    >...others have answered your actual fault!


    Contradicting each other as they do. Unless I misunderstood again.

    BB
     
    Big Bill, Oct 6, 2004
    #7
  8. On Wed, 06 Oct 2004 09:39:52 +0000, Big Bill wrote:

    > What about the hide scripts from older browsers thing? I thought that
    > was the reason for the comment tags. This isn't my script, I hasten to
    > add, I know very little of javascript. Like you couldn't tell.
    >
    > BB


    Steve is saying, leave the comment in, that's fine (to hide the script
    from old browsers), but put a newline in after the HTML comment "<!--":

    <SCRIPT language="javascript" type="text/javascript">
    <!--
    if (self != top)
    {top.location.href = self.location.href}
    -->
    </SCRIPT>

    It would seem that the Javascript parser treats "<!--" the same as "//" --
    an in-line comment.

    --
    Jeffrey Silverman

    ** Drop "PANTS" to reply by email
     
    Jeffrey Silverman, Oct 6, 2004
    #8
  9. Big Bill

    Big Bill Guest

    On Wed, 06 Oct 2004 07:32:18 -0400, Jeffrey Silverman
    <> wrote:

    >On Wed, 06 Oct 2004 09:39:52 +0000, Big Bill wrote:
    >
    >> What about the hide scripts from older browsers thing? I thought that
    >> was the reason for the comment tags. This isn't my script, I hasten to
    >> add, I know very little of javascript. Like you couldn't tell.
    >>
    >> BB

    >
    >Steve is saying, leave the comment in, that's fine (to hide the script
    >from old browsers), but put a newline in after the HTML comment "<!--":
    >
    ><SCRIPT language="javascript" type="text/javascript">
    > <!--
    > if (self != top)
    > {top.location.href = self.location.href}
    > -->
    ></SCRIPT>
    >
    >It would seem that the Javascript parser treats "<!--" the same as "//" --
    >an in-line comment.


    Thanks Jerry, at last something I can understand. I tried

    <SCRIPT language="javascript" type="text/javascript">
    <!--
    if (self != top) {top.location.href = self.location.href}
    //-->
    </SCRIPT>

    and that worked ok, so I tried

    <SCRIPT language="javascript" type="text/javascript">
    <!--
    if (self != top) {top.location.href = self.location.href}
    // -->
    </SCRIPT>

    and that was fine so I tried

    <SCRIPT language="javascript" type="text/javascript">
    <!--
    if (self != top) {top.location.href = self.location.href}
    -->
    </SCRIPT>

    and that worked too.
    I got bored after that.

    OK, thanks guys!

    BB
     
    Big Bill, Oct 6, 2004
    #9
  10. Big Bill

    Philip Ronan Guest

    On 6/10/04 12:32 pm, Jeffrey Silverman wrote:

    > Steve is saying, leave the comment in, that's fine (to hide the script
    > from old browsers), but put a newline in after the HTML comment "<!--":
    >
    > <SCRIPT language="javascript" type="text/javascript">
    > <!--
    > if (self != top)
    > {top.location.href = self.location.href}
    > -->
    > </SCRIPT>


    .... and as Disco Octopus said, you should close with "// -->", not just
    "-->"

    But you really should try and bear this in mind:

    1. There are NO CIRCUMSTANCES under which adding language="javascript"
    will serve any useful purpose. Period.

    2. The last browsers that required javascript and CSS stylesheet
    declarations to be hidden using HTML comments went out with the
    dinosaurs. Unless you're using HTML version 1.x, then there is ABSOLUTELY
    NO POINT in adding these comments because your HTML will break in these
    browsers anyway.

    Phil

    --
    Philip Ronan

    (Please remove the "z"s if replying by email)
     
    Philip Ronan, Oct 6, 2004
    #10
  11. Big Bill

    Neal Guest

    On Wed, 06 Oct 2004 12:58:12 +0100, Philip Ronan
    <> wrote:

    >
    > 2. The last browsers that required javascript and CSS stylesheet
    > declarations to be hidden using HTML comments went out with the
    > dinosaurs. Unless you're using HTML version 1.x, then there is
    > ABSOLUTELY
    > NO POINT in adding these comments because your HTML will break in
    > these
    > browsers anyway.



    HTML 1.x? Does that predate http://www.ietf.org/rfc/rfc1866.txt ?
     
    Neal, Oct 6, 2004
    #11
  12. Big Bill

    Philip Ronan Guest

    On 6/10/04 1:42 pm, Neal wrote:

    > HTML 1.x? Does that predate http://www.ietf.org/rfc/rfc1866.txt ?


    Oops, make that 2.x

    --
    Philip Ronan

    (Please remove the "z"s if replying by email)
     
    Philip Ronan, Oct 6, 2004
    #12
  13. Big Bill

    Big Bill Guest

    On Wed, 06 Oct 2004 12:58:12 +0100, Philip Ronan
    <> wrote:

    >On 6/10/04 12:32 pm, Jeffrey Silverman wrote:
    >
    >> Steve is saying, leave the comment in, that's fine (to hide the script
    >> from old browsers), but put a newline in after the HTML comment "<!--":
    >>
    >> <SCRIPT language="javascript" type="text/javascript">
    >> <!--
    >> if (self != top)
    >> {top.location.href = self.location.href}
    >> -->
    >> </SCRIPT>

    >
    >... and as Disco Octopus said, you should close with "// -->", not just
    >"-->"
    >
    >But you really should try and bear this in mind:
    >
    >1. There are NO CIRCUMSTANCES under which adding language="javascript"
    > will serve any useful purpose. Period.
    >
    >2. The last browsers that required javascript and CSS stylesheet
    > declarations to be hidden using HTML comments went out with the
    > dinosaurs. Unless you're using HTML version 1.x, then there is ABSOLUTELY
    > NO POINT in adding these comments because your HTML will break in these
    > browsers anyway.
    >
    >Phil


    You think? I only go by the guide in the validator. Or linter, if you
    will. And TIDY, not the only one I use, puts them in.

    BB
     
    Big Bill, Oct 6, 2004
    #13
  14. Big Bill

    Big Bill Guest

    On Wed, 06 Oct 2004 14:29:09 +0100, Philip Ronan
    <> wrote:

    >On 6/10/04 1:42 pm, Neal wrote:
    >
    >> HTML 1.x? Does that predate http://www.ietf.org/rfc/rfc1866.txt ?

    >
    >Oops, make that 2.x


    I think while you guys are all here, I'll just sneal quietly back to
    the engines group. Where disagreements are unknown. Small children
    play happily in the streets. Etc.

    BB
     
    Big Bill, Oct 6, 2004
    #14
  15. Big Bill

    Philip Ronan Guest

    On 6/10/04 3:38 pm, Big Bill wrote:

    > You think? I only go by the guide in the validator. Or linter, if you
    > will. And TIDY, not the only one I use, puts them in.
    >
    > BB


    Nah, this is really outdated stuff. There was a time, long ago, when
    language="Javascript" was the correct syntax. But since the language
    attribute is used everywhere in HTML to refer to human languages (like
    French or English), this was soon changed to type="text/javascript". The
    older browsers that expected a language attribute still work even if it
    isn't included, so there's just no need for it. If this "TIDY" thing is
    putting them in, then it really needs an overhaul.

    And on the subject of those <!-- and //--> things, if your documents use any
    super-advanced markup like <TABLE> (gasp!), then they will only display
    properly in browsers compliant with HTML 3.0+. Since HTML 3 requires
    browsers to not render the contents of <SCRIPT> and <STYLE> tags, there is
    really little point in trying to support earlier versions of HTML. They just
    aren't being used any more.

    Phil
    --
    Philip Ronan

    (Please remove the "z"s if replying by email)
     
    Philip Ronan, Oct 6, 2004
    #15
  16. Big Bill

    Steve Pugh Guest

    Jeffrey Silverman <> wrote:
    >On Wed, 06 Oct 2004 09:39:52 +0000, Big Bill wrote:
    >
    >> What about the hide scripts from older browsers thing? I thought that
    >> was the reason for the comment tags. This isn't my script, I hasten to
    >> add, I know very little of javascript. Like you couldn't tell.
    >>

    >Steve is saying, leave the comment in, that's fine (to hide the script
    >from old browsers),


    I am? That must be why I (twice) used the phrase " cargo cult
    nonsense".

    I recommend taking the comments out. But if Big Bill wants to leave
    them in just in case a Netscape 1 user happens along then that's his
    business.

    Steve
     
    Steve Pugh, Oct 6, 2004
    #16
  17. Big Bill

    Steve Pugh Guest

    Big Bill <> wrote:

    >What about the hide scripts from older browsers thing? I thought that
    >was the reason for the comment tags.


    It was the reason back in 1996 because Netscape 1 and Mosaic and other
    early browsers didn't know what this funny <script> element was and
    thus rendered its content as they would with any other unknown
    element.

    <script> was introduced in Netscape 2 and added to HTML 3.2 (though it
    was only fully defined in HTML 4.0). Any browser in use today - 2004,
    a full eight years later - would be incredibly deficient if it didn't
    know what the <script> element was and that it should not render its
    contents. Note that it doesn't have to understand JavaScript or any
    other scripting language, just understand what the <script> element
    is.

    And of course under XHTML those comments really are comments so you're
    commenting out all your script instructions unless you go to added
    lengths.

    As ever it's better to stick all the script in an external file.

    Steve
     
    Steve Pugh, Oct 6, 2004
    #17
  18. Big Bill

    Big Bill Guest

    On Wed, 06 Oct 2004 16:33:56 +0100, Philip Ronan
    <> wrote:

    >On 6/10/04 3:38 pm, Big Bill wrote:
    >
    >> You think? I only go by the guide in the validator. Or linter, if you
    >> will. And TIDY, not the only one I use, puts them in.
    >>
    >> BB

    >
    >Nah, this is really outdated stuff. There was a time, long ago, when
    >language="Javascript" was the correct syntax. But since the language
    >attribute is used everywhere in HTML to refer to human languages (like
    >French or English), this was soon changed to type="text/javascript". The
    >older browsers that expected a language attribute still work even if it
    >isn't included, so there's just no need for it. If this "TIDY" thing is
    >putting them in, then it really needs an overhaul.


    You never heard of Tidy? Or Dave Ragett of associated with the W3C
    fame?

    >And on the subject of those <!-- and //--> things, if your documents use any
    >super-advanced markup like <TABLE> (gasp!), then they will only display
    >properly in browsers compliant with HTML 3.0+. Since HTML 3 requires
    >browsers to not render the contents of <SCRIPT> and <STYLE> tags, there is
    >really little point in trying to support earlier versions of HTML. They just
    >aren't being used any more.


    Um, I'm not a languagey-type person (guess who my favourite vampire
    slayer is), but I do want things to be syntactically correct to some
    kind of standard. One that the engines will note with approval. And
    Gawd knows how out of date they are. So I try to fix the (always)
    broken sites I'm given to work with up to scratch. Are you saying that
    with javascript I shouldn't? Actually in a lot of instances you'd be
    right as I note that a lot of Amazon code, for instance, sends any
    kind of validator into seizures.

    BB

    >Phil
     
    Big Bill, Oct 6, 2004
    #18
  19. Big Bill

    Big Bill Guest

    On Wed, 06 Oct 2004 18:18:11 +0100, Steve Pugh <> wrote:

    >Jeffrey Silverman <> wrote:
    >>On Wed, 06 Oct 2004 09:39:52 +0000, Big Bill wrote:
    >>
    >>> What about the hide scripts from older browsers thing? I thought that
    >>> was the reason for the comment tags. This isn't my script, I hasten to
    >>> add, I know very little of javascript. Like you couldn't tell.
    >>>

    >>Steve is saying, leave the comment in, that's fine (to hide the script
    >>from old browsers),

    >
    >I am? That must be why I (twice) used the phrase " cargo cult
    >nonsense".


    Gee I'm so happy I know where to go for a clear concensus on things.

    >I recommend taking the comments out. But if Big Bill wants to leave
    >them in just in case a Netscape 1 user happens along then that's his
    >business.


    I only recently deleted Mosaic. True!

    BB
     
    Big Bill, Oct 6, 2004
    #19
  20. Big Bill

    Big Bill Guest

    On Wed, 06 Oct 2004 18:23:11 +0100, Steve Pugh <> wrote:

    > Big Bill <> wrote:
    >
    >>What about the hide scripts from older browsers thing? I thought that
    >>was the reason for the comment tags.

    >
    >It was the reason back in 1996 because Netscape 1 and Mosaic and other
    >early browsers didn't know what this funny <script> element was and
    >thus rendered its content as they would with any other unknown
    >element.
    >
    ><script> was introduced in Netscape 2 and added to HTML 3.2 (though it
    >was only fully defined in HTML 4.0). Any browser in use today - 2004,
    >a full eight years later - would be incredibly deficient if it didn't
    >know what the <script> element was and that it should not render its
    >contents. Note that it doesn't have to understand JavaScript or any
    >other scripting language, just understand what the <script> element
    >is.
    >
    >And of course under XHTML those comments really are comments so you're
    >commenting out all your script instructions unless you go to added
    >lengths.
    >
    >As ever it's better to stick all the script in an external file.
    >
    > Steve


    Mkay then.

    BB
     
    Big Bill, Oct 6, 2004
    #20
    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. HK
    Replies:
    0
    Views:
    289
  2. Sharp Tool

    Riddle me this

    Sharp Tool, Nov 6, 2005, in forum: Java
    Replies:
    29
    Views:
    1,188
    John C. Bollinger
    Nov 10, 2005
  3. magmike

    Database Results Riddle

    magmike, Aug 5, 2004, in forum: HTML
    Replies:
    18
    Views:
    683
    Toby Inkster
    Aug 8, 2004
  4. CBFalconer

    Re: Riddle

    CBFalconer, Jan 20, 2005, in forum: C++
    Replies:
    0
    Views:
    411
    CBFalconer
    Jan 20, 2005
  5. Juha Haataja

    Solving the Einstein's Riddle in Python

    Juha Haataja, May 24, 2004, in forum: Python
    Replies:
    10
    Views:
    892
    Christos TZOTZIOY Georgiou
    May 25, 2004
Loading...

Share This Page