<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Why can't you say &amp;lt;/script&amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx</link><description>Because it ends the script block, of course.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Why can't you say &amp;lt;/script&amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617906</link><pubDate>Mon, 05 Jun 2006 17:15:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617906</guid><dc:creator>LarryOsterman</dc:creator><description>And of course the last is how the MySpace &amp;quot;worm&amp;quot; worked (it wasn't a worm, it was a self-propogating cross-site-scripting exploit).&lt;br&gt;</description></item><item><title>re: Why can't you say &amp;amp;lt;/script&amp;amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617922</link><pubDate>Mon, 05 Jun 2006 17:37:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617922</guid><dc:creator>Einars Lielmanis</dc:creator><description>Or, alternatively, you could just hide the script in the HTML comments,
&lt;br&gt;&amp;lt;script type="text/javascript"&amp;gt;
&lt;br&gt;&amp;lt;!--
&lt;br&gt;document.write('&amp;lt;script&amp;gt;alert("Rules!")&amp;lt;/script&amp;gt;');
&lt;br&gt;--&amp;gt;
&lt;br&gt;&amp;lt;/script&amp;gt;
&lt;br&gt;&lt;br&gt;&lt;div class="post"&gt;[&lt;i&gt;That just swaps out one problem for
another. Then the title of this article becomes "Why can't you say
--&amp;gt; in a script block?": &lt;CODE&gt;&amp;lt;script&amp;gt;&amp;lt;!-- document.write("Click
here --&amp;gt;"); ... --&amp;gt;&amp;lt;/script&amp;gt;&lt;/CODE&gt; -Raymond&lt;/i&gt;]&lt;/div&gt;</description></item><item><title>re: Why can't you say &amp;amp;amp;lt;/script&amp;amp;amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617927</link><pubDate>Mon, 05 Jun 2006 17:41:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617927</guid><dc:creator>Martin Probst</dc:creator><description>Oh please. Don't post something like this if it's wrong!
&lt;br&gt;
&lt;br&gt;In HTML it's illegal to use the '&amp;lt;' character in plain text.
You always need to escape it as '&amp;amp;lt;'. (I hope this survives
the comment form). Just like in XML and XHTML. It has never been legal.
And all HTML parsers are required to transcode it properly.
&lt;br&gt;
&lt;br&gt;So do use &amp;amp;lt;/SCRIPT&amp;gt;. Also use &amp;amp;lt;SCRIPT&amp;gt;
for that matter, and use "if (5 &amp;amp;lt; 10) ...". Everything else
is not HTML. It will work because the browsers know that HTML authors
are ignorant, but as this is a non-standard fixup, you can't rely on it
working and maybe the fixup starts to work in a different way later on?
Then don't complain about these browsers all rendering your page in
wrong way ...
&lt;br&gt;
&lt;br&gt;Nice issue with your headline though - the day all earth comes down
in ashes, the sole thing surviving will be a wrongly double-escaped
string ;-)
&lt;br&gt;&lt;br&gt;&lt;div class="post"&gt;[&lt;i&gt;Fixed the headline. Stupid autoposter. I need to talk to the person who wrote it. Oh wait, that's me. (And I fixed your &amp;lt; characters.) -Raymond&lt;/i&gt;]&lt;/div&gt;</description></item><item><title>re: Why can't you say &amp;lt;/script&amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617931</link><pubDate>Mon, 05 Jun 2006 17:47:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617931</guid><dc:creator>Adam</dc:creator><description>Except that &amp;quot;&amp;lt;!--&amp;quot; isn't valid javascript.&lt;br&gt;&lt;br&gt;If you want a safe alternative, use an external script file:&lt;br&gt;&lt;br&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;script.js&amp;quot; /&amp;gt;&lt;br&gt;</description></item><item><title>re: Why can't you say &amp;lt;/script&amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617939</link><pubDate>Mon, 05 Jun 2006 17:57:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617939</guid><dc:creator>BryanK</dc:creator><description>Except that's not going to work according to the XML standard:&lt;br&gt;&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://www.mit.edu/~ddcc/xhtmlref/text.html"&gt;http://www.mit.edu/~ddcc/xhtmlref/text.html&lt;/a&gt;&lt;br&gt;&lt;br&gt;&amp;quot;Encasing scripts and style sheets in comment delimiters (&amp;lt;!-- --&amp;gt;) does not officially work. According to the W3C, the parser may remove all comments before passing the code onto the user agent. In addition, C-like languages, including Javascript, have a decrement operator (&amp;quot;--&amp;quot;) that just happens to be the SGML comment delimiter.&amp;quot;&lt;br&gt;&lt;br&gt;Also:&lt;br&gt;&lt;br&gt;&amp;quot;Interestingly, XML has a special construct designed to deal with the script and style sheet problem. Anything wrapped between &amp;quot;&amp;lt;![CDATA[&amp;quot; and &amp;quot;]]&amp;gt;&amp;quot; is treated as CDATA. Thus, using the same example, the fragment of code could be rewritten this way:&lt;br&gt;&lt;br&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt; &amp;lt;![CDATA[ if (h &amp;amp;&amp;amp; i) j(); ]]&amp;gt; &amp;lt;/script&amp;gt;&lt;br&gt;&lt;br&gt;The problem with this solution is that not many browsers understand this synatx either. You might try wrapping the CDATA markers inside comments. (Use the comments of your scripting or style-sheet language, mind you. If you use the SGML-style comments, all sorts of nastiness may ensue.) The other problem is that if your script or style-sheet actually contains the sequence &amp;quot;]]&amp;gt;,&amp;quot; you're out of luck again.&amp;quot;&lt;br&gt;&lt;br&gt;And the last quote from that page:&lt;br&gt;&lt;br&gt;&amp;quot;Lastly, your best solution may be just to use external scripts and style sheets, avoiding this whole big mess.&amp;quot;&lt;br&gt;&lt;br&gt;Which is what I do.&lt;br&gt;&lt;br&gt;(This is also part of the &amp;quot;Unobtrusive Javascript&amp;quot; idea, which holds that putting *any* script code inside your HTML file is a mistake. &amp;nbsp;This is for the same reason that using *any* inline style attribute is a mistake -- if you want to change the style (or the code), you'll potentially have to edit all your HTML files, instead of the stylesheet (or script file).)&lt;br&gt;&lt;br&gt;&amp;lt;script type=&amp;quot;text/ecmascript&amp;quot; src=&amp;quot;blah.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;&lt;br&gt;works just fine. &amp;nbsp;;-)</description></item><item><title>Except alternative that thing</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617950</link><pubDate>Mon, 05 Jun 2006 18:11:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617950</guid><dc:creator>Yoz</dc:creator><description>Just to add to the cavalcade of &amp;quot;except that&amp;quot; or &amp;quot;alternately&amp;quot; comments - document.write() is not just an outdated method, it actually won't work on proper XHTML documents. See here for more info:&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://ln.hixie.ch/?start=1091626816&amp;amp;count=1"&gt;http://ln.hixie.ch/?start=1091626816&amp;amp;count=1&lt;/a&gt;&lt;br&gt;&lt;br&gt;Instead, you should remove the need for writing &amp;lt;/SCRIPT&amp;gt; by not actually writing the raw HTML in your code, and creating the node the proper DOM way:&lt;br&gt;&lt;br&gt;var scriptNode = document.createElement(&amp;quot;script&amp;quot;);&lt;br&gt;scriptNode.setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/javascript&amp;quot;);&lt;br&gt;&lt;br&gt;etc.&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617952</link><pubDate>Mon, 05 Jun 2006 18:15:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617952</guid><dc:creator>BryanK</dc:creator><description>Oops, my previous reply was to Einars Lielmanis.&lt;br&gt;&lt;br&gt;Other stuff posted since I started writing that:&lt;br&gt;&lt;br&gt;Adam: &amp;nbsp;Right idea, but your self-closing script tag doesn't work in IE6SP1 (not sure on SP2). &amp;nbsp;For some reason, that browser requires two separate tags; otherwise it won't &amp;quot;see&amp;quot; the script. &amp;nbsp;You can't combine them like that, even though there's no content and IIRC XML says you should be able to in that case.&lt;br&gt;&lt;br&gt;And Martin Probst: not all browsers actually parse entity references in script code, even though the content of the script tag is supposed to be &amp;quot;parsed CDATA&amp;quot;. &amp;nbsp;I know some don't change &amp;amp;amp;&amp;amp;amp; into &amp;amp;&amp;amp; before passing it to the script engine, for instance. &amp;nbsp;I'm not sure about &amp;amp;lt; though -- it may work.&lt;br&gt;&lt;br&gt;OTOH, external scripts &amp;quot;always&amp;quot; work. &amp;nbsp;If you need to handle events, hook them up in window.onload inside the external script, and unhook them in window.onunload if you need to do that to prevent a memory leak.&lt;br&gt;&lt;br&gt;Yoz: &amp;nbsp;Yep. &amp;nbsp;I'm not sure how to add content to that script tag in the DOM, though -- perhaps:&lt;br&gt;&lt;br&gt;var txtNode = document.createTextNode(&amp;quot;script code here&amp;quot;);&lt;br&gt;scriptNode.appendChild(txtNode);&lt;br&gt;&lt;br&gt;would work? &amp;nbsp;Never tried it (my scripts have always been &amp;quot;static&amp;quot;; I've never tried creating one from another script).</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617956</link><pubDate>Mon, 05 Jun 2006 18:20:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617956</guid><dc:creator>Grant</dc:creator><description>[So how do you work around this aspect of HTML parsing? You have to find an alternate way of expressing the string you want. Typically, this is done by breaking in up into two strings that you then reassemble:&lt;br&gt;&lt;br&gt;document.write(&amp;quot;&amp;lt;SCRIPT&amp;gt;blahblah&amp;lt;/SCRI&amp;quot;+&amp;quot;PT&amp;gt;&amp;quot;);]&lt;br&gt;&lt;br&gt;Another solution, recommended by comp.lang.javascript, is to escape the forward slash in the &amp;lt;/SCRIPT&amp;gt; tag:&lt;br&gt;&lt;br&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br&gt;document.write('&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;alert(&amp;quot;hi&amp;quot;);&amp;lt;\/script&amp;gt;');&lt;br&gt;&amp;lt;/script&amp;gt;&lt;br&gt;&lt;br&gt;It should work in all web browsers.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617970</link><pubDate>Mon, 05 Jun 2006 18:38:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617970</guid><dc:creator>A/C</dc:creator><description>Wouldn't the parser start a new script block at the document.write(&amp;quot;&amp;lt;SCRIPT&amp;gt;... and then end *that* one when it finds the &amp;lt;/SCRIPT&amp;gt; ?</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617981</link><pubDate>Mon, 05 Jun 2006 18:59:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617981</guid><dc:creator>James Hart</dc:creator><description>According to the HTML language spec (&lt;a rel="nofollow" target="_new" href="http://www.w3.org/TR/html401/appendix/notes.html#notes-specifying-data"&gt;http://www.w3.org/TR/html401/appendix/notes.html#notes-specifying-data&lt;/a&gt;), it's not just &amp;lt;/script&amp;gt; that should break out of a script element - it's the sequence '&amp;lt;/'. They give the following as an example of script that won't work:&lt;br&gt;&lt;br&gt; &amp;nbsp; &amp;nbsp;&amp;lt;SCRIPT type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;document.write (&amp;quot;&amp;lt;EM&amp;gt;This won't work&amp;lt;/EM&amp;gt;&amp;quot;)&lt;br&gt; &amp;nbsp; &amp;nbsp;&amp;lt;/SCRIPT&amp;gt;&lt;br&gt;&lt;br&gt;In reality, this script actually -does- work, at least in IE6 and Firefox...&lt;br&gt;&lt;br&gt;What's worrying, to my mind, though, is that following the absolute letter of the HTML spec, the character sequence '&amp;lt;/' is simply illegal in a &amp;lt;script&amp;gt; element. Bad news if you want to specify a Javascript regex literal that matches strings ending in a less-than character.&lt;br&gt;&lt;br&gt;In the course of investigating this I found out that the following actually appears to be syntactically valid Javascript, although it is, of course, semantically utter nonsense:&lt;br&gt;&lt;br&gt;&amp;lt;script&amp;gt;&lt;br&gt; var a = / &amp;lt;/i&amp;gt; 1;&lt;br&gt; document.write (a);&lt;br&gt;&amp;lt;/script&amp;gt;&lt;br&gt;&lt;br&gt;Imagine you're an XML-ish parser. That does look -awfully- like a well-formedness-breaking closing &amp;lt;/i&amp;gt; tag nested inside that &amp;lt;script&amp;gt; element, doesn't it..?</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#617997</link><pubDate>Mon, 05 Jun 2006 19:18:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617997</guid><dc:creator>Adam</dc:creator><description>BrianK: Oh, thanks for that. Unfortunately, I can't test for and work around every browser incompatibility there is, especially for browsers that aren't available on my platform. The empty &amp;lt;script&amp;gt; tag works fine in Firefox and Konqueror, and is fine according to the w3c validator, so that's good enough for me.&lt;br&gt;&lt;br&gt;I'm also able to really not care as my site is perfectly functional if you have javascript turned off (or just not available), so the worst that will happen for IE users is that they won't get some of the non-content-related-but-flashy doodahs.&lt;br&gt;&lt;br&gt;I guess users of Explorer had better keep putting that pressure on their vendor to improve support for the spec if they want their doodahs though! :)&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#618023</link><pubDate>Mon, 05 Jun 2006 19:53:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:618023</guid><dc:creator>Maurits</dc:creator><description>CDATA is the way to go...&lt;br&gt;&lt;br&gt;Q: How do you embed ]]&amp;gt; in a script block?&lt;br&gt;A: ]]&amp;amp;gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#618062</link><pubDate>Mon, 05 Jun 2006 20:55:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:618062</guid><dc:creator>BryanK</dc:creator><description>Maurits: But if it's CDATA, is the &amp;amp;gt; going to be parsed as an entity reference and replaced with the appropriate characters before being passed on to the script engine? &amp;nbsp;Based on what I know of XML, I don't think it will be.&lt;br&gt;&lt;br&gt;Adam: Yeah, I wish I didn't have to do that either; it's several characters that I wouldn't have to type every time I refer to a script. &amp;nbsp;Unfortunately for me, everyone in the company uses IE6 SP1 or SP2, and they'd get a little annoyed if the flashy stuff that I told them I was doing didn't show up. &amp;nbsp;Even if it wasn't required to use the site (and it isn't), they'd still be annoyed.&lt;br&gt;&lt;br&gt;(Actually, I'm not sure whether &amp;lt;script /&amp;gt; works in the IE7 betas either. &amp;nbsp;Haven't tried it.)</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#618068</link><pubDate>Mon, 05 Jun 2006 20:59:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:618068</guid><dc:creator>Maurits</dc:creator><description>Well, there's this way too:&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://en.wikipedia.org/wiki/CDATA_section"&gt;http://en.wikipedia.org/wiki/CDATA_section&lt;/a&gt;&lt;br&gt;&lt;br&gt;&amp;lt;![CDATA[foo]]]]&amp;gt;&amp;lt;![CDATA[&amp;gt;bar]]&amp;gt;&lt;br&gt;&lt;br&gt;becomes: foo]]&amp;gt;bar</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#618102</link><pubDate>Mon, 05 Jun 2006 21:40:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:618102</guid><dc:creator>Sven Groot</dc:creator><description>&amp;gt; var scriptNode = document.createElement(&amp;quot;script&amp;quot;); &lt;br&gt;&amp;gt; scriptNode.setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/javascript&amp;quot;); &lt;br&gt;&lt;br&gt;Actually, that also won't work in XHTML, provided you did use the application/xhtml+xml MIME-type. To complicate matters further, you must use document.createElementNS and pass the proper XHTML namespace, document.createElement won't work in a true XHTML-compliant browser.&lt;br&gt;&lt;br&gt;And it's not necessary to use setAttribute, you can just do scriptNode.type = &amp;quot;text/javascript&amp;quot; (that's a DOM Level 1 attribute).&lt;br&gt;&lt;br&gt;And BrianK, I expect using createTextNode should work for setting the script, although I have not actually tried this myself.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#618371</link><pubDate>Tue, 06 Jun 2006 01:06:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:618371</guid><dc:creator>Sebastian Redl</dc:creator><description>Still various errors here. The HTML 4.01 spec says:&lt;br&gt;&lt;br&gt;---&lt;br&gt;Although the STYLE and SCRIPT elements use CDATA for their data model, for these elements, CDATA must be handled differently by user agents. Markup and entities must be treated as raw text and passed to the application as is. The first occurrence of the character sequence &amp;quot;&amp;lt;/&amp;quot; (end-tag open delimiter) is treated as terminating the end of the element's content. In valid documents, this would be the end tag for the element.&lt;br&gt;---&lt;br&gt;&lt;br&gt;Entities must be treated as raw text; &amp;amp;lt; in a script block is just &amp;amp;lt; to a script, and any browser replacing the entity is not conformant.&lt;br&gt;&lt;br&gt;To the HTML spec, at least. In XHTML, the content type of the script element is PCDATA, so there markup and entities do get parsed. Great, huh?&lt;br&gt;&lt;br&gt;I agree with previous comments: just make the script external.</description></item><item><title>Pourquoi ne peut-on pas mettre de &amp;amp;lt;/script&amp;amp;gt; dans un script ?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#618918</link><pubDate>Tue, 06 Jun 2006 12:23:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:618918</guid><dc:creator>Blog-a-Styx</dc:creator><description>Un petit article sympa que je viens de lire sur un nouveau blog trouv&amp;amp;#233; ce (dur) matin&amp;amp;#160;: celui de Raymond...</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#618960</link><pubDate>Tue, 06 Jun 2006 13:59:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:618960</guid><dc:creator>Jack V.</dc:creator><description>If you were changing the script tag syntax, surely the simplest mod would be to be able to specify the closing tag, a la &amp;lt;&amp;lt; in perl. Eg.&lt;br&gt;&lt;br&gt;&amp;lt;script close=&amp;quot;THISISREALLYTHEEND&amp;quot;&amp;gt;&lt;br&gt;// &amp;lt;/script&amp;gt; That didn't matter&lt;br&gt;THISISREALLYTHEEND&amp;gt;&lt;br&gt;&lt;br&gt;You might or might not specify where the close appear on the line, or if you can/must have a &amp;lt;/script&amp;gt; after it as well.&lt;br&gt;&lt;br&gt;But the HTML parser only needs to know one new thing, and everyone who invents a language where THISISREALLYTHEEND is the assignment operator can just choose another string, maybe a multiiline string.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#618984</link><pubDate>Tue, 06 Jun 2006 15:27:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:618984</guid><dc:creator>silkio</dc:creator><description>To say that you can't determine the language of the script and hence the comment/quoting style is pretty lame.&lt;br&gt;&lt;br&gt;Clearly IE makes assumptions about the script type ANYWAY, so why not just use that format (the assumed script language) to decide what quotes/comments are?</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#619052</link><pubDate>Tue, 06 Jun 2006 17:13:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:619052</guid><dc:creator>Neil</dc:creator><description>Don't forget that each external script file is a synchronous network request that must be processed before parsing of your page can complete (document.write can't be deferred).</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#619065</link><pubDate>Tue, 06 Jun 2006 17:23:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:619065</guid><dc:creator>Adam</dc:creator><description>Jack, Silkio: Consider applications that want to parse HTML that aren't full-blown browsers. Or even browsers that don't support scripting. Do you think all browsers should have to fully parse even JavaScript just to be able to find the end script tag, even if they're not going to _do_ anything with the script?&lt;br&gt;&lt;br&gt;HTML is _NOT_ a programming language. It is a _document markup_ language. A parser should be able to determine where the markup sections start and stop with /relative/ simplicity.&lt;br&gt;&lt;br&gt;&lt;br&gt;On top of this, even according to the HTML specs (particular wording here taken from HTML 4.01 Appendix B.1 at &lt;a rel="nofollow" target="_new" href="http://www.w3.org/TR/html4/appendix/notes.html"&gt;http://www.w3.org/TR/html4/appendix/notes.html&lt;/a&gt; but most versions of HTML have a section like it) a user-agent should be able to handle markup it doesn't recognise:&lt;br&gt;&lt;br&gt;* If a user agent encounters an element it does not recognize, it should try to render the element's content.&lt;br&gt;&lt;br&gt;Of course, rendering content shouldn't apply to elements in the &amp;lt;head&amp;gt; of a document, but such a user-agent should still be able to reliably _find_ _the_ _end_ of the element it needs to ignore.&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#619066</link><pubDate>Tue, 06 Jun 2006 17:27:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:619066</guid><dc:creator>Adam</dc:creator><description>Neil: The external script file (as with external style sheet files) should be cacheable, even if the rest of your site isn't. e.g. if it's some kind of database-backed shopping site, etc...&lt;br&gt;&lt;br&gt;Using external script files can decrease your total bandwidth usage quite a bit, and may well speed up all page views to your site bar the first if the script(s) are large.&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#619174</link><pubDate>Tue, 06 Jun 2006 19:45:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:619174</guid><dc:creator>Gabe</dc:creator><description>Jack, in order for the &amp;quot;heredoc&amp;quot; (the name of the Unix shell feature that Perl includes) paradigm to work, it would need to have been included in HTML back in the early 1990s. Why?&lt;br&gt;&lt;br&gt;Well, an HTML parser that doesn't know about scripts would never know to look for the sentinel at the end of the script. The only way for the naive parser to be able to find it is if the 'close' attribute were already defined as an option on every single element. That way a parser would automatically look for a 'close' attribute on every tag, whether it understands the tag or not.&lt;br&gt;&lt;br&gt;Similarly, a 'render=false' option would have been nice also. That way in-line scripts and stylesheets would have a way to indicate to downlevel browsers that they should not render the contents of their tags.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620123</link><pubDate>Wed, 07 Jun 2006 04:11:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620123</guid><dc:creator>silkio</dc:creator><description>Adam:&lt;br&gt;&lt;br&gt;Like I said, if the browser chooses not to process the javascript, then there is no issue. The only confusion occurs is where PART of your javascript is processed due to a script tag in the middle of it.&lt;br&gt;&lt;br&gt;I'm not asking non-&amp;quot;script&amp;quot; processing browsers to start processing it, I'm saying that if they DO process the script, and DO execute part of it, we have a right to be a little upset that they decided to be ignorant about the script tag embedded inside.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620379</link><pubDate>Wed, 07 Jun 2006 10:05:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620379</guid><dc:creator>Gabe</dc:creator><description>Sorry silkio, but it still won't work. Any browser that doesn't know your scripting language won't know when to stop parsing as script and when to start parsing as HTML again.&lt;br&gt;&lt;br&gt;A browser that doesn't understand ANY scripts will render them all as text anyway, so it won't care about whether the &amp;lt;/SCRIPT&amp;gt; tag embedded in them should be rendered or not.&lt;br&gt;&lt;br&gt;However any browser (Lynx comes to mind) that knows about scripts will never want to render the content of the script block whether it knows how to parse the language or not. You want to be able to write:&lt;br&gt;&lt;br&gt;&amp;lt;script language=&amp;quot;PerlScript&amp;quot;&amp;gt;&lt;br&gt;# this is a &amp;lt;script&amp;gt;&amp;lt;/script&amp;gt; block&lt;br&gt;document.write(qq!&amp;lt;script&amp;gt;$script&amp;lt;/script&amp;gt;!)&lt;br&gt;&amp;lt;/script&amp;gt;&lt;br&gt;&lt;br&gt;Unfortunately, only browsers that understand PerlScript know how to parse it properly. All others would show &amp;quot;block document.write(qq!!)&amp;quot;. Since PerlScript it a pluggable script engine, my browser understands it but yours might not.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620382</link><pubDate>Wed, 07 Jun 2006 10:15:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620382</guid><dc:creator>Adam</dc:creator><description>Silkio:&lt;br&gt;&lt;br&gt;But this isn't just about what browsers that _do_ understand javascript have to do.&lt;br&gt;&lt;br&gt;You can't say &amp;quot;&amp;lt;/script&amp;gt;&amp;quot; in a script block because browsers/parsers/applications that _don't_ understand scripts still have to be able to tell where the end of the script block is so they can process the rest of the page correctly.&lt;br&gt;&lt;br&gt;If you allow &amp;quot;&amp;lt;/script&amp;gt;&amp;quot; in the script block in any form (either in a literal string, or in some other case) then _all_ these other programs need to understand enough javascript to be able to spot a literal string, and a regular expression, and a comment, etc, etc, etc... Basically, they need to fully understand javascript in order to find the &amp;quot;real&amp;quot; end of the script.&lt;br&gt;&lt;br&gt;For this reason, you cannot _allow_ &amp;quot;&amp;lt;/script&amp;gt;&amp;quot; tags inside a script, in order for non-script processors to be able to understand HTML.&lt;br&gt;&lt;br&gt;Therefore, even browsers that _do_ understand scripts cannot allow this either. If such browsers did support embedded &amp;quot;&amp;lt;/script&amp;gt;&amp;quot; tags, people would write code that did that, test it in their browser, see that it worked as expected and assume it was fine. However, non-script-enabled browsers would just break, having found the &amp;quot;&amp;lt;/script&amp;gt;&amp;quot; tag that they thought was the end and trying to process the rest of the script as HTML.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620396</link><pubDate>Wed, 07 Jun 2006 10:34:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620396</guid><dc:creator>silkio</dc:creator><description>Gabe/Adam:&lt;br&gt;&lt;br&gt;What I'm saying is that if the browser processes the script at all, it can't pretend that it doesn't know how to find comments/text.&lt;br&gt;&lt;br&gt;That is to say, the following code:&lt;br&gt;&lt;br&gt;============&lt;br&gt;&amp;lt;script&amp;gt;&lt;br&gt;alert(1);&lt;br&gt;//&amp;lt;/script&amp;gt;&lt;br&gt;alert(2);&lt;br&gt;&amp;lt;/script&amp;gt;&lt;br&gt;=============&lt;br&gt;&lt;br&gt;should produce either:&lt;br&gt; - alert 1&lt;br&gt; - alert 2&lt;br&gt;&lt;br&gt;or&lt;br&gt; - NOTHING.&lt;br&gt;&lt;br&gt;i.e, the processor has _already_ figured out what language it is, so why does it sit back and declare &amp;quot;oh no, i don't know how to find comments, i'll just end now.&amp;quot;&lt;br&gt;&lt;br&gt;&lt;br&gt;and about lynx; even though it's textbased it still needs (or at least _should_) process script ... obviously not all script is for visual purposes.&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620423</link><pubDate>Wed, 07 Jun 2006 11:31:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620423</guid><dc:creator>Adam</dc:creator><description>Silkio&amp;gt; &amp;quot;and about lynx; even though it's textbased it still needs (or at least _should_) process script ... obviously not all script is for visual purposes.&amp;quot;&lt;br&gt;&lt;br&gt;Ah - now I see _where_ our differences lie. :)&lt;br&gt;&lt;br&gt;This is the statment I disagree with. And I'm not conviced why it should be the case. IMO, an HTML parser should be able to parse HTML without having to be able to parse JavaScript too. Why do you think otherwise?&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620442</link><pubDate>Wed, 07 Jun 2006 11:52:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620442</guid><dc:creator>Adam</dc:creator><description>Also, not all HTML parsers are in web browsers.&lt;br&gt;&lt;br&gt;What about spiders, like googlebot? Should that have to be able to parse javascript so that it doesn't think you have the text &amp;quot;alert(2);&amp;quot; in your web page?&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620488</link><pubDate>Wed, 07 Jun 2006 13:12:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620488</guid><dc:creator>silkio</dc:creator><description>Adam:&lt;br&gt;&lt;br&gt;I don't think browsers should have to parse javascript or any script. What I'm saying, though, is that if they _TRY_, then must assume a certain type of script to do so.&lt;br&gt;&lt;br&gt;IE will assume javascript, if it's not specified.&lt;br&gt;&lt;br&gt;For example, the following won't popup a message box in IE unless &amp;quot;type='vbscript'&amp;quot; is specified:&lt;br&gt;&lt;br&gt;============&lt;br&gt;&amp;lt;script&amp;gt;&lt;br&gt;MsgBox(&amp;quot;1&amp;quot;)&lt;br&gt;&amp;lt;/script&amp;gt;&lt;br&gt;============&lt;br&gt;&lt;br&gt;I still think you are missing my main point ... that if the browser DOES try and guess the language (which IE _clearly_ does) then it's a lie to say you don't know how to resolve comments and strings.&lt;br&gt;&lt;br&gt;Spiders will need to process javascript anyway, but if they don't, that's totally fine, they can just find the &amp;lt;/script&amp;gt; block where it lies. Other script-aware HTML parsers have no programmatic excuse for acting so ignorant.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620504</link><pubDate>Wed, 07 Jun 2006 13:45:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620504</guid><dc:creator>Adam</dc:creator><description>Silkio&amp;gt; &amp;quot;Spiders will need to process javascript anyway ...&amp;quot;&lt;br&gt;&lt;br&gt;Why? Please explain the logic underlying that conclusion.&lt;br&gt;&lt;br&gt;Silkio&amp;gt; &amp;quot;...but if they don't, that's totally fine, they can just find the &amp;lt;/script&amp;gt; block where it lies.&amp;quot;&lt;br&gt;&lt;br&gt;Huh? But if you have an embedded &amp;lt;/script&amp;gt; tag, that's the one that non-javascript-aware HTML parsers will hit. They _can't_ find the proper end of the script block. That's the whole point! That's why embedded &amp;lt;/script&amp;gt; tags _must_ be disallowed.&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620511</link><pubDate>Wed, 07 Jun 2006 13:53:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620511</guid><dc:creator>silkio</dc:creator><description>Adaim:&lt;br&gt;&lt;br&gt;:|&lt;br&gt;&lt;br&gt;&amp;gt; Silkio&amp;gt; &amp;quot;Spiders will need to process &lt;br&gt;&amp;gt; javascript anyway ...&amp;quot;&lt;br&gt;&amp;gt; &lt;br&gt;&amp;gt; Why? Please explain the logic underlying that &lt;br&gt;&amp;gt; conclusion.&lt;br&gt;&lt;br&gt;Consider the page consisting of:&lt;br&gt;&amp;lt;script language=&amp;quot;javascript&amp;quot;&amp;gt;document.location = 'realhomepage.html';&amp;lt;/script&amp;gt;&lt;br&gt;&lt;br&gt;my point was not &amp;quot;All bots should process javascript so that can discover valid ending script tags&amp;quot; it was &amp;quot;a smart bot will process javascript [which isn't really relevant to our discussion anyway]&amp;quot;.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&amp;gt; Silkio&amp;gt; &amp;quot;...but if they don't, that's totally &amp;gt; fine, they can just find the &amp;lt;/script&amp;gt; block &amp;gt; where it lies.&amp;quot;&lt;br&gt;&amp;gt; &lt;br&gt;&amp;gt; Huh? But if you have an embedded &amp;lt;/script&amp;gt; &lt;br&gt;&amp;gt; tag, that's the one that non-javascript-aware&lt;br&gt;&amp;gt; &amp;nbsp;HTML parsers will hit. They _can't_ find the&lt;br&gt;&amp;gt; &amp;nbsp;proper end of the script block. That's the &lt;br&gt;&amp;gt; whole point! That's why embedded &amp;lt;/script&amp;gt; &lt;br&gt;&amp;gt; tags _must_ be disallowed. &lt;br&gt;&lt;br&gt;Because different parsers may see different html output based on what scripting language they support? Sure, I agree. That's seems like an okay reason to disallow it ... not great, but ...&lt;br&gt;&lt;br&gt;All I was initially trying to say is that Raymond's comment that he doesn't know HOW to find the script tag is not true. IE *can* figure out if it's a valid ending tag if it wanted to, but it doesn't want to. It's not a programming problem (like Raymond was trying to say) it's a logical one ... :)</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620703</link><pubDate>Wed, 07 Jun 2006 14:39:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620703</guid><dc:creator>Adam</dc:creator><description>I give up.&lt;br&gt;&lt;br&gt;I'll just say that I'd hate to try to write an HTML parser one weekend in a world where you controlled the HTML standards. :)&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#620877</link><pubDate>Wed, 07 Jun 2006 18:50:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620877</guid><dc:creator>Ross Bemrose</dc:creator><description>&amp;quot;Consider the page consisting of:&lt;br&gt;&amp;lt;script language=&amp;quot;javascript&amp;quot;&amp;gt;document.location = 'realhomepage.html';&amp;lt;/script&amp;gt;&amp;quot;&lt;br&gt;&lt;br&gt;You don't need Javascript to do redirects. &amp;nbsp;Use either an HTTP header or a &amp;lt;meta&amp;gt; tag to redirect instead.</description></item><item><title>re: Why can't you say &amp;amp;amp;lt;/script&amp;amp;amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#621370</link><pubDate>Thu, 08 Jun 2006 03:38:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:621370</guid><dc:creator>silkio</dc:creator><description>Ross: Yes, but that's not at all the point.
&lt;br&gt;
&lt;br&gt;Adam: :) Come on now, I'm really not trying to say that all parsers
have to implement script-parsing, I am just saying that if they do,
they should be able to detect a script tag.&lt;br&gt;&lt;br&gt;&lt;div class="post"&gt;[&lt;i&gt;Where is the /script tag in the following:&lt;br&gt;&lt;pre&gt;&amp;lt;SCRIPT LANGUAGE="leandra"&amp;gt;&lt;br&gt;.&amp;lt;/SCRIPT&amp;gt;'&amp;lt;/SCRIPT&amp;gt;"&amp;lt;/SCRIPT&amp;gt;;(&amp;lt;/SCRIPT&amp;gt;)&lt;br&gt;\&amp;lt;/SCRIPT&amp;gt;#&amp;lt;/SCRIPT&amp;gt;&lt;br&gt;&amp;lt;/SCRIPT&amp;gt;#&amp;lt;/SCRIPT&amp;gt;&lt;br&gt;&lt;/pre&gt;
How would you write the parser that figures out which of those "&amp;lt;/SCRIPT&amp;gt;"s is the real /SCRIPT tag? -Raymond&lt;/i&gt;]&lt;/div&gt;</description></item><item><title>re: Why can't you say &amp;lt;/script&amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#621475</link><pubDate>Thu, 08 Jun 2006 05:51:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:621475</guid><dc:creator>silkio</dc:creator><description>Raymond: What do you mean? I don't know "leandre" language, so I would take the first one.
&lt;br&gt;
&lt;br&gt;If I did know leandra language, I would try and parse that script
using it's grammar. If I failed (i.e invalid token or something), i'd
take the next /script tag at the index of where i failed. if I passed,
I'd know where it ends and also take the next /script tag.
&lt;br&gt;
&lt;br&gt;...
&lt;br&gt;
&lt;br&gt;?
&lt;BR&gt;&lt;BR&gt;&lt;DIV CLASS=post&gt;[&lt;I&gt;And that's my point. You don't know leandra. The browser doesn't know leandra. How should it know which is the real /script tag? -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: Why can't you say &amp;amp;lt;/script&amp;amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#621627</link><pubDate>Thu, 08 Jun 2006 09:21:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:621627</guid><dc:creator>silkio</dc:creator><description>If it doesn't know leandra it takes the first tag.
&lt;br&gt;
&lt;br&gt;This is what I've been saying all along. If you can't/dont want to process the language, then it doesn't need to try.&lt;br&gt;&lt;br&gt;&lt;div class="post"&gt;[&lt;i&gt;In
other words, you are okay with a web page parsing in two completely
different ways depending on whether the browser supports the leandra
language. Good luck writing an HTML validator! And if the browser does support it, it'll have to load the leandra parser in order to find the correct end tag, which completely ruins the DEFER attribute. Wait a second, i'm just repeating myself. This is exactly what I wrote in the main article! -Raymond&lt;/i&gt;]&lt;/div&gt;</description></item><item><title>re: Why can't you say &amp;lt;/script&amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#621933</link><pubDate>Thu, 08 Jun 2006 13:56:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:621933</guid><dc:creator>silkio</dc:creator><description>Raymond:
&lt;br&gt;
&lt;br&gt; In the OP you said it _wasn't possible_. Clearly it is possible; that's _all_ I was trying to say.
&lt;br&gt;
&lt;br&gt; I've never used the "DEFER" attribute so I'll take your word that it will become useless.
&lt;br&gt;
&lt;br&gt; I don't mind the way it currently works, [not that I'd expect a
chance if I didn't] and I don't neccessarily think that it would be bad
thing to ask the language for the ending /script tag. It seems to be
the most intuitive.
&lt;br&gt;
&lt;br&gt; Either way, all I was trying to point out is that your OP is wrong ...
&lt;br&gt;&lt;br&gt;&lt;DIV CLASS=post&gt;[&lt;I&gt;Allow me to clarify for nitpickers: It's not possible without sacrificing obvious principles like "It should be possible to write HTML such that every browser will agree on how it is parsed." Because if you lose that, then how can you write HTML? -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#622066</link><pubDate>Thu, 08 Jun 2006 16:45:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:622066</guid><dc:creator>AC</dc:creator><description>Silkio: Are you under some kind of delusion that javascript is either part of the HTML spec, or that HTML has some kind of special relationship with javascript that it doesn't have with other scripting languages (such as leandre)?&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#622903</link><pubDate>Fri, 09 Jun 2006 00:46:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:622903</guid><dc:creator>silkio</dc:creator><description>AC: no.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#622970</link><pubDate>Fri, 09 Jun 2006 01:47:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:622970</guid><dc:creator>AC</dc:creator><description>Oh.&lt;br&gt;&lt;br&gt;So in that case, for the following HTML that you posted:&lt;br&gt;&lt;br&gt;&amp;lt;script&amp;gt;&lt;br&gt;alert(1);&lt;br&gt;//&amp;lt;/script&amp;gt;&lt;br&gt;alert(2);&lt;br&gt;&amp;lt;/script&amp;gt;&lt;br&gt;&lt;br&gt;You think that:&lt;br&gt;&lt;br&gt;1) A js-aware HTML parser should see the first &amp;lt;/script&amp;gt; as a comment, the &amp;quot;alert(2);&amp;quot; as part of the script, and the second &amp;lt;/script&amp;gt; as the end-of-script tag.&lt;br&gt;&lt;br&gt;2) A non-js-aware HTML parser should see the first &amp;lt;/script&amp;gt; as the end-of-script, the &amp;quot;alert(2);&amp;quot; as text in the enclosing element (should be the enclosing head element, where text is not allowed), and the second &amp;lt;/script&amp;gt; as an invalid close tag that doesn't match an open tag.&lt;br&gt;&lt;br&gt;Is that correct? Two validating HTML parsers, which both fully support the HTML 4 spec, should be able to treat the same HTML document differently, and for one to find the document valid, and the other to find it broken?&lt;br&gt;&lt;br&gt;Which parser is correct? Both? Is one more correct than the other? If one *is* more correct than the other, why should the &amp;quot;less correct&amp;quot; parser not need to be fixed to be &amp;quot;more correct&amp;quot;?&lt;br&gt;</description></item><item><title>re: Why can't you say &amp;lt;/script&amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623026</link><pubDate>Fri, 09 Jun 2006 02:19:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623026</guid><dc:creator>silkio</dc:creator><description>AC. &lt;BR&gt;&lt;BR&gt;As I said in my earlier posts, I don't think this is the best way for the parses to operate; I was only commenting on Raymonds wording in the OP. &lt;BR&gt;&lt;BR&gt;- &lt;BR&gt;&lt;BR&gt;To answer your question though; the processing of javascript can change the document that the parsers parse _anyway_, so what's the big deal? &lt;BR&gt;&lt;BR&gt;Both parsers are correct; one just implements JS and is able to understand the document better.&lt;BR&gt;&lt;BR&gt;&lt;DIV CLASS=post&gt;[&lt;I&gt;I stand by my original statement: "If a language parser were required to locate the end of the script block, it would be impossible to parse past this point." If a leandra parser is required in order to parse past the &amp;lt;script language="leandra"&amp;gt; block and you don't have a leandra parser, then you can't parse any further. The statement is practically a tautology. -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: Why can't you say &amp;lt;/script&amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623052</link><pubDate>Fri, 09 Jun 2006 02:33:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623052</guid><dc:creator>silkio</dc:creator><description>Raymond: What's wrong with this process: &lt;BR&gt;&lt;BR&gt;- get script language &lt;BR&gt;- if known lang, request /script index &lt;BR&gt;- if unknown lang, /script index = first from this point &lt;BR&gt;&lt;BR&gt;..? &lt;BR&gt;&lt;BR&gt;(Other then the fact it will lead to different parsing structure depending on known languages.)&lt;BR&gt;&lt;BR&gt;&lt;DIV CLASS=post&gt;[&lt;I&gt;That's like asking, "What's wrong with this key aside from the fact that it doesn't open the lock?" -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623055</link><pubDate>Fri, 09 Jun 2006 02:36:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623055</guid><dc:creator>AC</dc:creator><description>OK. If that particular script does nothing than execute those two alerts, and does not change the document in any way, and assuming that the rest of the document is otherwise valid, would you say that the document should be considered valid HTML 4?&lt;br&gt;&lt;br&gt;If you think the document is valid HTML 4, how can you claim that the non-js-aware parser is correct if it misidentifes the document as being invalid?&lt;br&gt;&lt;br&gt;(And as an aside - what would be a good way for the non-js-aware parser to operate?)&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623068</link><pubDate>Fri, 09 Jun 2006 02:47:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623068</guid><dc:creator>silkio</dc:creator><description>Raymond:&lt;br&gt;&lt;br&gt;Ok. We disagree then.&lt;br&gt;&lt;br&gt;&lt;br&gt;AC: As I said, this method has issues, but it's not impossible. Clearly the fact that the tags you choose to use are up to the script will then change the way your document validates. I don't actually think it's bad that document validation depends on script; browsers interpret script as well, and you can currently easily make a valid document invalid with the simplest bit scripting.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623094</link><pubDate>Fri, 09 Jun 2006 03:07:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623094</guid><dc:creator>AC</dc:creator><description>Humour me. This exact document:&lt;br&gt;&lt;br&gt;&amp;lt;!DOCTYPE HTML PUBLIC&lt;br&gt; &amp;nbsp; &amp;nbsp;&amp;quot;-//W3C//DTD HTML 4.01//EN&amp;quot;&lt;br&gt; &amp;nbsp; &amp;nbsp;&amp;quot;&lt;a rel="nofollow" target="_new" href="http://www.w3.org/TR/html4/strict.dtd&amp;quot;&amp;gt;"&gt;http://www.w3.org/TR/html4/strict.dtd&amp;quot;&amp;gt;&lt;/a&gt;&lt;br&gt;&amp;lt;html&amp;gt;&lt;br&gt;&amp;lt;head&amp;gt;&lt;br&gt;&amp;lt;title&amp;gt;test&amp;lt;/title&amp;gt;&lt;br&gt;&amp;lt;script&amp;gt;&lt;br&gt;alert(1);&lt;br&gt;//&amp;lt;/script&amp;gt;&lt;br&gt;alert(2);&lt;br&gt;&amp;lt;/script&amp;gt;&lt;br&gt;&amp;lt;/head&amp;gt;&lt;br&gt;&amp;lt;body&amp;gt;&lt;br&gt;&amp;lt;p&amp;gt;test&amp;lt;/p&amp;gt;&lt;br&gt;&amp;lt;/body&amp;gt;&lt;br&gt;&amp;lt;/html&amp;gt;&lt;br&gt;&lt;br&gt;Should it be considered valid HTML? Yes or no?&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623096</link><pubDate>Fri, 09 Jun 2006 03:12:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623096</guid><dc:creator>AC</dc:creator><description>Doh. Missed 'type=&amp;quot;text/javascript&amp;quot;' attribute from the &amp;lt;script&amp;gt; tag. Pretend it's there.&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623105</link><pubDate>Fri, 09 Jun 2006 03:20:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623105</guid><dc:creator>silkio</dc:creator><description>AC: Well it depends if the validator implements the javascript language, doesn't it :)&lt;br&gt;&lt;br&gt;I am the validator, and I happen to understand javascript, so yes, I will call that document valid.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623116</link><pubDate>Fri, 09 Jun 2006 03:38:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623116</guid><dc:creator>AC</dc:creator><description>Therefore, are you saying that an HTML parser that correctly follows every last paragraph of the HTML spec, but is not js-aware, is an incorrect HTML parser[0]?&lt;br&gt;&lt;br&gt;Don't you think there's a slight internal inconsistency with that?&lt;br&gt;&lt;br&gt;(Have you ever been to Milliways restaurant?)&lt;br&gt;&lt;br&gt;[0] Or do you think that the correctness of a parser can be measured other than by whether it follows the spec it is implementing, and whether it can determine if a document also follows that spec?&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623117</link><pubDate>Fri, 09 Jun 2006 03:39:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623117</guid><dc:creator>GregM</dc:creator><description>No, it doesn't depend if the validator implements the javascript language.&lt;br&gt;&lt;br&gt;The definition of HTML 4.01 (as defined in (&amp;lt;!DOCTYPE HTML PUBLIC &amp;quot;-//W3C//DTD HTML 4.01//EN&amp;quot; &amp;quot;&lt;a rel="nofollow" target="_new" href="http://www.w3.org/TR/html4/strict.dtd&amp;quot;&amp;gt;"&gt;http://www.w3.org/TR/html4/strict.dtd&amp;quot;&amp;gt;&lt;/a&gt;) does not understand javascript. &lt;br&gt;&lt;br&gt;Therefore, by definition, this is not a valid HTML document. &amp;nbsp;Period. &amp;nbsp;End of story. &amp;nbsp;No amount of asserting that the parser understands multiple languages will make it a valid 4.01 document.&lt;br&gt;&lt;br&gt;It may be a valid Silkio-browser document, but it is not a valid HTML 4.01 document.&lt;br&gt;</description></item><item><title>re: Why can't you say &amp;amp;lt;/script&amp;amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623123</link><pubDate>Fri, 09 Jun 2006 03:44:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623123</guid><dc:creator>silkio</dc:creator><description>Guys: &lt;BR&gt;&lt;BR&gt;You're not getting it. I've said in almost every post of mine that this method has issues. I agree that a non-js-parsing validator will see this documetn as invalid. That's what I said would happen. &lt;BR&gt;&lt;BR&gt;I even said I don't think this is a great way of doing things; but on othe other hand, is it so bad that scripting languages - something which can CURRENTLY affect the structure of a doc - become a part of the document validation process? I don't think so. &lt;BR&gt;&lt;BR&gt;OF COURSE this method does not meet the current HTML 4.01 spec. &lt;BR&gt;&lt;BR&gt;To clarify: If "silkio-validating" was implemented, the spec would need to be changed.&lt;BR&gt;&lt;BR&gt;
&lt;DIV class=post&gt;[&lt;I&gt;Today, script cannot affect the parsing of a document. Sure, running the script may modify the document, but that's not at issue here. The issue here is parsing. And if parsing is dependent on something outside the HTML author's control, how can an HTML author write markup with any confidence? -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623137</link><pubDate>Fri, 09 Jun 2006 03:56:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623137</guid><dc:creator>silkio</dc:creator><description>Raymond: Right.&lt;br&gt;&lt;br&gt;The suggestion here is that &amp;quot;parsing&amp;quot; of a html document should include executing and processing of the script areas.&lt;br&gt;&lt;br&gt;(Yes, there are issues with this. Putting it lightly...)</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623141</link><pubDate>Fri, 09 Jun 2006 04:01:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623141</guid><dc:creator>AC</dc:creator><description>HOW?&lt;br&gt;&lt;br&gt;I'm trying to be hypothetical and move away from the current spec into a &amp;quot;how would you have this work then&amp;quot; kind of vibe, and trying to understand where you're coming from, but...&lt;br&gt;&lt;br&gt;How would you change the spec so, such that a validating parser could possibly be written without being internally inconsistent?&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623156</link><pubDate>Fri, 09 Jun 2006 04:13:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623156</guid><dc:creator>silkio</dc:creator><description>AC:&lt;br&gt;&lt;br&gt;By having the spec include a spec for processing javascript? But then you'd have to have specs for all scripting languages ...&lt;br&gt;&lt;br&gt;So the spec could just say : &amp;quot;execute and process script to get actual page structure&amp;quot;.&lt;br&gt;&lt;br&gt;Then each validator/&amp;quot;parser&amp;quot; can implement as many scripting languages as it likes, and validate away, meeting the spec!&lt;br&gt;&lt;br&gt;If it doesn't have any scripting langauges, then that's fine, it can't get the desired page structure and will call the doc invalid due to unknown script. [of course it can still _display_ as much of the doc as it could].&lt;br&gt;&lt;br&gt;Obviously all hypothetical, and written on the fly, so give me a break if I made a typo/omission :)&lt;br&gt;&lt;br&gt;Hopefully it's clear ...</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623490</link><pubDate>Fri, 09 Jun 2006 09:34:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623490</guid><dc:creator>AC</dc:creator><description>So, you are actually saying that you want to change the spec so that it's impossible to write a parser that can reliably tell which parts of the document are _not_ script, and therefore have _no way_ of knowing which parts of the document it is even _meant_ to process.&lt;br&gt;&lt;br&gt;No, I can make that simpler. You are actually saying that you want to change the spec so that HTML is impossible to reliably parse.&lt;br&gt;&lt;br&gt;And you don't think that just having to break up &amp;quot;&amp;lt;/script&amp;gt;&amp;quot; in a string literal or comment is the simpler and more sensible thing to do? Even though you're smart enough to not speak in l33t, to write with correct grammar and basically to be all articulate and everything?&lt;br&gt;&lt;br&gt;But..., but..., but..., *head explodes*&lt;br&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623561</link><pubDate>Fri, 09 Jun 2006 11:18:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623561</guid><dc:creator>silkio</dc:creator><description>AC: [if you can still read after that exploison].&lt;br&gt;&lt;br&gt;The spec isn't change so that it's impossible to reliably pass. You can still reliably find the script blocks of a document. All you do is write your parser so that it does NOT implement a scripting language, and simply goes for the first &amp;nbsp;/script it finds.&lt;br&gt;&lt;br&gt;If you DO choose to write a parser that understands a given script language, your parser just must request the ending script tag from the appropriate language parser.&lt;br&gt;&lt;br&gt;I don't see how this suggests a spec which is impossible to reliably parse.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623708</link><pubDate>Fri, 09 Jun 2006 15:10:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623708</guid><dc:creator>BryanK</dc:creator><description>You may be able to &amp;quot;reliably&amp;quot; (though I'm not sure how you can justify that part) find the script block. &amp;nbsp;But you *cannot* reliably find the end. &amp;nbsp;You can find *an* end, but if it's not always *the* *same* end, then you do *not* have a reliable parser.&lt;br&gt;&lt;br&gt;IMO, in order to &amp;quot;reliably&amp;quot; parse anything, you need to always get the same parse tree, no matter what optional (or &amp;quot;extra&amp;quot;) parts of the spec you support. &amp;nbsp;If you don't, then the spec has problems.&lt;br&gt;&lt;br&gt;Note that I'm not talking about one parser always getting the same result, I'm talking about *all* (compliant) parsers always getting the same result as each other.</description></item><item><title>re: Why can't you say &amp;lt;/script&amp;gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623722</link><pubDate>Fri, 09 Jun 2006 15:26:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623722</guid><dc:creator>silkio</dc:creator><description>BryanK:
&lt;br&gt;
&lt;br&gt;Different "types" of parses will get different results. Javascript-enabled parsers will get _better_ results.
&lt;br&gt;
&lt;br&gt;-
&lt;br&gt;
&lt;br&gt;Think about what the spec is trying to do. Scripts have a special
ability in HTML; they can modify the code that is parsed. They can
create more, or delete some, or change parts. This affects the end
result to the user, and the reason we even _have_ validators is so that
the end user sees the same thing everywhere [in all browsers].
&lt;br&gt;
&lt;br&gt;The point is, by processing/parsing the SCRIPT of a document, you can gain a better understanding of it.
&lt;br&gt;
&lt;br&gt;This can only be a good thing.
&lt;br&gt;
&lt;br&gt;You are saying it's bad because a given validator understands a given doc better then another; I say, what's wrong with that? 
&lt;br&gt;
&lt;br&gt;It's hardly a crime to have a tool that gives more accurate results!
&lt;br&gt;&lt;br&gt;&lt;DIV CLASS=post&gt;[&lt;I&gt;What about a language where it is legal to just say "&amp;lt;/script&amp;gt; outside of quotation marks? The parser for that language would never find the end of the script block since any time it saw "&amp;lt;/script&amp;gt;" it would say, "Oh, yeah, that's legal in my language. I'm still parsing." -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#623902</link><pubDate>Fri, 09 Jun 2006 18:35:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:623902</guid><dc:creator>BryanK</dc:creator><description>What's wrong with that is that there's no way to *reliably* come up with HTML that includes script code (reliably as in: people always see the same thing before the script runs). &amp;nbsp;Today, people see different &amp;quot;end&amp;quot; web pages depending on whether they have JS enabled or not, yes. &amp;nbsp;But if your version of HTML existed, people that didn't have JS enabled would (potentially) see a bunch of gobbledeygook code in the middle of the HTML, which may also include various other elements that *weren't* supposed to be output.&lt;br&gt;&lt;br&gt;How is it better to (1) not have the script be able to modify the document, *and* *also* (2) see a bunch of text you don't understand and don't care about? &amp;nbsp;That goes against every &amp;quot;fail gracefully&amp;quot; maxim in existence. &amp;nbsp;JS is supposed to fail gracefully if the user-agent doesn't understand it; so is CSS.&lt;br&gt;&lt;br&gt;&amp;gt; It's hardly a crime to have a tool that gives more accurate results!&lt;br&gt;&lt;br&gt;No, but it is a crime to artificially cripple tools just because they don't understand the language you used.&lt;br&gt;&lt;br&gt;My basic axiom is: &amp;nbsp;A document should be either valid all the time, or invalid all the time. &amp;nbsp;You *can't* make a document's validity depend on how well the validator understands script. &amp;nbsp;The whole *point* of validation is to give your document a prayer of showing up the same way regardless of browser (as long as the browser complies with the standard). &amp;nbsp;If you suddenly introduce some feature that makes random script text show up in some browsers, you've broken that.</description></item><item><title>re: Why can't you say &lt;/script&gt; in a script block?</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#624187</link><pubDate>Fri, 09 Jun 2006 22:07:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:624187</guid><dc:creator>David Conrad</dc:creator><description>&amp;quot;You're not getting it. I've said in almost every post of mine that this method has issues.&amp;quot;&lt;br&gt;&lt;br&gt;I get it. You're saying that this method is both broken and not-broken. But I think it's actually broken OR not-broken. Specifically, broken.&lt;br&gt;</description></item><item><title>Pour quelques Javascripts de plus</title><link>http://blogs.msdn.com/oldnewthing/archive/2006/06/05/617901.aspx#4512623</link><pubDate>Wed, 22 Aug 2007 19:30:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4512623</guid><dc:creator>Da Scritch Net Works</dc:creator><description>&lt;p&gt;C'est bien joli de mettre des effets partout... Mais si &amp;#231;a doit rendre un site tr&amp;#232;s lent, la java en vaut-elle le lag ? Pendant la reconception de mon site, je me suis furieusement gratt&amp;#233; la t&amp;#234;te pour vous.&lt;/p&gt;
</description></item></channel></rss>