You are here: Re: cdata and javascript « HTML « IT news, forums, messages
Re: cdata and javascript

Posted by Jeff on 10/30/96 12:01

cwdjrxyz wrote:
> On Jan 26, 4:55 pm, Jeff <jeff@spam_me_not.com> wrote:
>> I V wrote:
>>> On Sat, 26 Jan 2008 16:49:13 -0500, Jeff wrote:
>>>> Why not? If I want to validate the page as I'm working on it I won't
>>>> have to wade through the 47 errors the validator thinks it sees in the
>>>> javascript where I'm assembling bits of html.
>>> What validator are you using? In HTML (but not XHTML), the content of a
>>> script element is already considered CDATA, so the validator shouldn't
>>> complain about HTML fragments in the script. I've just checked the W3C's
>>> validator and it thinks this is valid, for instance:
>> The W3C's.
>>
>> What happens is that I'm concatenating strings (content += ...) and
>> it's complaining about closing tags that aren't open (the are opened on
>> another line). I didn't expect that, I validated it because of the
>> problem in the next thread and I was surprised to see all that. I've
>> never used CDATA so I though it was time to learn. I was wrong!
>>
>> I think I'll just take cwdjrxyz'z advice and ignore them for now. It
>> will of course wind up in an external file when I get done with writing it.
>
> See http://www.htmlhelp.com/tools/validator/problems.html and read the
> section in it concerning javascript errors. One of the most common
> validation errors is not backslashing when using a document.write
> within a javascript.

Thanks, that explains that exactly.


This reference discusses why this is required.
> However the script will work on many, if not most, browsers in current
> use if you neglect to do so.


I find that interesting. Do you know of any specific examples where
the browser and not the validator would complain? It's always nice to
catch problems rather than vice versa.

Jeff
>
>
>>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
>>> "http://www.w3.org/TR/html4/strict.dtd">
>>> <html>
>>> <head>
>>> <title>I AM YOUR DOCUMENT TITLE REPLACE ME</title>
>>> <script type="text/javascript">
>>> document.write('<foobar>');
>>> </script>
>>> </head>
>>> <body>
>>> <p>
>>> Something in the body.
>>> </p>
>>> </body>
>>> </html>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация