- From: Jukka K. Korpela <jkorpela@cs.tut.fi>
- Date: Sun, 30 Jan 2005 11:18:31 +0200 (EET)
- To: DjMafia <barrerad@gye.satnet.net>
- Cc: www-validator@w3.org
On Sun, 30 Jan 2005, DjMafia wrote: > <script type="text/javascript"> if (!chatterbox || chatterbox != 'ok') { > var txt = "This <a href="http://chatter.flooble.com/">flooble > chatterbox</a> is" Quick answer: put all script code into an external file that you refer to via a src attribute in a script element. Alternatively, unless you have some particular reason to use XHTML, switch to HTML, where the problem is smaller (you only need to worry about things like </a>, which you can write as <\/a> in JavaScript). In XHTML, which you seem to be using, a script element's content is #PCDATA (parsed character data), and hence e.g. "<a" is interpreted as starting an element (but no elements are allowed inside a script element). In principle, you could replace any occurrence of "<" inside a script element by "<". This would be fine as far as XHTML is concerned. But this would not be practical, since Internet Explorer does not actually "do XHTML" but e.g. interprets the content of a script element by classic HTML rules (to the extent it plays by any rules). Here's a tricky way of dealing with the problem if the use of an external script file is for some reason excluded: In your Javascript code, define a variable (effectively a constant) with "<" as its value, without using the "<" as itself of course, e.g. var lt = '\x3c'; Then use this variable instead of the "<" character inside the script. You cannot use a variable inside a quoted string, so you need to split strings e.g. as follows: var txt = 'This ' + lt + 'a href="http://chatter.flooble.com/">flooble ' + 'chatterbox' + lt + '/a is'; Note that the validator's FAQ entry http://validator.w3.org/docs/help.html#faq-javascript is partly dated since it refers to http://www.htmlhelp.com/tools/validator/problems.html#script which is a simple and understandable explanation but only applies to HTML, where the problem is more limited. > I would really appreciate a quick answer for this problem... deadline is > February 2... please... _Especially_ if you need quick help, you should post the URL of the page in your message. It is generally more useful than anything else in identifying the problem. -- Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/
Received on Sunday, 30 January 2005 09:19:05 UTC