Validation error

J

Joe Blow

I have the following in my page:

</head>

<body bgcolor="#ffffff">
<script type="text/javascript" language=Javascript>
<!--
if (navigator.appName.indexOf("Netscape") != -1 &&
parseInt(navigator.appVersion) < 5) {
document.write("<div class=\"arial\" align=\"center\">")
document.write("<br><br><b>You may experience difficulties viewing this
site.<br>To provide an improved service to most readers, this site is
designed to be read using the latest web browsers.</b></div><br><br>");
}
//-->
</script>

It is used to detect older Netscape browsers and display the text.

It fails to validate at validator.w3.org - It says that the </b> and
</div> tags weren't open.

Any suggestions?
 
T

Toby Inkster

Joe said:
<script type="text/javascript" language=Javascript>
<!--
if (navigator.appName.indexOf("Netscape") != -1 &&
parseInt(navigator.appVersion) < 5) {
document.write("<div class=\"arial\" align=\"center\">")
document.write("<br><br><b>You may experience difficulties viewing this
site.<br>To provide an improved service to most readers, this site is
designed to be read using the latest web browsers.</b></div><br><br>");
}
//-->
</script>

Javascript isn't allowed to contain "</". That magic string counts as "end
of the script data".

Use:
document.write("<"); document.write("/b><"); document.write("/div><br><br>");
 
N

Neal

I have the following in my page:

</head>

<body bgcolor="#ffffff">
<script type="text/javascript" language=Javascript>
<!--
if (navigator.appName.indexOf("Netscape") != -1 &&
parseInt(navigator.appVersion) < 5) {
document.write("<div class=\"arial\" align=\"center\">")
document.write("<br><br><b>You may experience difficulties viewing this
site.<br>To provide an improved service to most readers, this site is
designed to be read using the latest web browsers.</b></div><br><br>");
}
//-->
</script>

It is used to detect older Netscape browsers and display the text.

It fails to validate at validator.w3.org - It says that the </b> and
</div> tags weren't open.

Any suggestions?

I suggest you determine the real purpose and results of this code, and
decide ultimately that it's not worth including.
 
J

Jukka K. Korpela

Toby Inkster said:
Javascript isn't allowed to contain "</". That magic string counts as
"end of the script data".

No, the character pair "</" is allowed inside a script element.
It's "</b" that creates a syntax error. The script element's content
model is CDATA, which means that it may contain any string, treated as
unparsed string of characters as far as HTML is concerned, except that
the first occurrence of an end tag open delimiter (ETAGO, that is "</")
immediately followed by a name character (A - Z, a - z) is recognized and
terminates the string. And for a document to be valid, that construct
must be part of the end tag that terminates the element, </script>.

(That's HTML. In XHTML it's different, more confusing.)

And for this syntactic issue, it is completely irrelevant what the
content of the script element is (e.g., whether it is JavaScript code or
something else).
Use:
document.write("<"); document.write("/b><");
document.write("/div><br><br>");

Well, that would be one way of solving the problem, if the problem
mattered.
 
K

Karl Groves

It is used to detect older Netscape browsers and display the text.

The script is junk, and the purpose behind it is junk.
Unless you have individual log data that suggests otherwise, you're
expending far too much effort for <1% of your visitors.
People who make business decisions based on <1% of their customers are bad
businesspeople.

-Karl
 
D

Dylan Parry

Spake Joe Blow unto thee:
Any suggestions?

People using older versions of Netscape _expect_ to see junk when they
visit most sites. I wouldn't bother including that script at all, but if
you really insist replace it with:

<script type="text/javascript" language=Javascript>
<!--
if (navigator.appName.indexOf("Netscape") != -1 &&
parseInt(navigator.appVersion) < 5) {
document.write("<div class=\"arial\" align=\"center\">")
document.write("<br><br><b>You may experience difficulties viewing this
site.<br>To provide an improved service to most readers, this site is
designed to be read using the latest web browsers.<\/b><\/div><br><br>");
}
//-->
</script>

Which is almost the same as your version, but with the </b> and </div>
escaped to become <\/b> and <\/div>.
 

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

Forum statistics

Threads
473,797
Messages
2,569,647
Members
45,377
Latest member
Zebacus

Latest Threads

Top