Riddle me this javascript please.

B

Big Bill

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
 
D

Disco Octopus

Big said:
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?
 
B

Big Bill

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
 
S

Steve Pugh

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
 
S

SpaceGirl

Big said:
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 #
 
B

Big Bill

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
 
B

Big Bill

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
 
J

Jeffrey Silverman

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.
 
B

Big Bill

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
 
P

Philip Ronan

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
 
N

Neal

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 ?
 
B

Big Bill

... 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
 
B

Big Bill

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
 
P

Philip Ronan

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
 
S

Steve Pugh

Jeffrey Silverman said:
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
 
S

Steve Pugh

Big Bill said:
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
 
B

Big Bill

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
 
B

Big Bill

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
 
B

Big Bill

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top