Should we continue to hide script or not ?

A

Asterbing

Should we continue to hide the inline script content or not ?

I mean using this well known syntax :

<script type="text/javascript"><!--
document.write("test");
//--></script>

rather than this one :

<script type="text/javascript">
document.write("test");
</script>

Kowing a <noscript> tag exists somewhere in the page.

What's your opinion ?
 
R

rf

Asterbing said:
Should we continue to hide the inline script content or not ?

I mean using this well known syntax :

<script type="text/javascript"><!--
document.write("test");
//--></script>

A few minutes browsing *any* web related newsgroup would have given you the
answer.

There is no need to "hide" script using HTML comments, and there has not
been any need to since Netscape 2. We are now in the next century
 
A

Asterbing

There is no need to "hide" script using HTML comments, and there has not
been any need to since Netscape 2. We are now in the next century

Right, thanks
 
S

shimmyshack

Right, thanks

having said that though there is the related topic of how to present
inline javascript in xhtml, so that xml parsers don't trip up on it,
its another subject but amounts to using the following syntax:

<script type="text/javascript">
//<![CDATA[

//]]>
</script>

you will thus not get warnings when validating your strict xhtml doc,
when you use < and other characters the parser might otherwise trip up
on.
 
R

Richard Cornford

shimmyshack said:
having said that though there is the related topic of how to present
inline javascript in xhtml, so that xml parsers don't trip up on it,

No such issue exists. First there is almost no commercial use of (real)
XHTML because IE browsers do not support it at all. Second, inline
script element content in XHTML is unambiguously PCDATA and so the rules
for how it will be handled by an XML parser are certain, and so you know
that inline scripts need to be entified so that mark-up significant
characters can be properly handled. And third, given 2 most people would
recommend only using imported scripts with XMTML.
its another subject but amounts to using the following syntax:

<script type="text/javascript">
//<![CDATA[

//]]>
</script>

If this was (real) XHTML then the javascript 'end of line' comment
sequences would be redundant. The fact that they are here betrays the
fact that this has nothing to do with XHTML at all but is actually about
how to allow an inline script in a tag-soup HTML file that is attempting
to give the illusion of bang XHTML non-problematic in the event of the
mark-up being exposed to an XML or XHTML validator. As validating
mark-up which is not expected to ever be interpreted as XMTML with an
XHTML validator a pointless and irrational activity there is little
point in conjuring up any "hide script" incantation for that context.

In addition, while the occurrences of XML mark-up significant characters
in scripts is high, wrapping any old arbitrary block of script code in
<!CDATA[ ... ]]> mark-up does not fully address the issue in a real
XHTML context as ']]>' is a valid construct in javascript (i.e.
something like - if(a[b[c]]>2){ ... } -)
you will thus not get warnings when validating your strict
xhtml doc,

Strict or transitional XHTML is an irrelevance. You may still get
warnings if the script includes the sequence ']]>' in its source code,
and the 'end of line' comments are not necessary (or event relevant) to
getting the mark-up to validate.
when you use < and other characters the parser might otherwise
trip up on.

What you are describing here is how to stop the CDATA contents of script
elements in documents that are really (tag soup) HTML interfering with
the illusion that those documents are XHTML in a way that will not cause
issues when those documents are interpreted as (tag-soup) HTML by the
receiving browser. But as the real consequences of applying the illusion
of XHTML to documents that are really HTML is mostly to spread confusion
as to the real nature of those documents the whole practice is
irrational, counter-productive, folly.

Richard.
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top