You are here: Re: xhtml strict javascript problem trying to use "id" in plane of "name" attribute « HTML « IT news, forums, messages
Re: xhtml strict javascript problem trying to use "id" in plane of "name" attribute

Posted by cwdjrxyz on 08/28/07 03:18

On Aug 27, 7:07 pm, meya...@gmail.com wrote:
> I have tried to resolve this in several ways that I have found on the
> internet, but none seems to work. Here is the shortened code which is
> a website displaying a webcam. The .jpg is overwritten with new image
> from the camera. This code works, but does not pass W3C XHTML
> STRICT.
>
> 1) How can I keep this working, and change the attribute to "id" so is
> passes STRICT?
> 2) While I'm asking questions, what purpose does the "//" in the //<!
> [CDATA[ line perform? When I read the spec (http://www.w3.org/TR/
> xhtml1/) it only says to use <![CDATA[ ?
>
> MY CODE ***************************************
> ***************************************************
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
> <head>
> <meta http-equiv="content-type" content="text/html; charset=utf-8" />
> <title>Camsite</title>
> <script type="text/javascript">
> //<![CDATA[
>
> function refreshIMG()
>
> {
> var trimmedPath=new Array();
>
> var currentPath=document.image3.src;
> trimmedPath=currentPath.split("?");
> document.image3.src = trimmedPath[0] + "?" +
> Math.random();
>
> setTimeout("refreshIMG()", 8*1000);
> }
>
> //]]>
> </script>
> </head>
>
> <body onload="refreshIMG()">
> <h4>CAM_3</h4>
> <div>
> <img class="cam" src="images/cam_3.jpg" width="320"
> height="240" name="image3" alt="Image loading ..." id="image3" />
> </div>
> </body>
> </html>

CDATA is an xml thing. Xhtml is a hybrid that handles both html and
xml. Javascript often contains some things that are not allowed in
xml. Thus if you serve the xhtml properly as application/xhtml+xml,
the page is parsed as xml and you get an error message rather than
viewing the page if the script contains things that are forbidden in
xml. Enclosing the script in the open and close CDATA tags tells the
xhtml parser not to check the enclosed section for xml errors, since
it is something other than xhtml. You can avoid all of this be using
an external script in the manner usual for html. Notice the // before
the opening and closing CDATA tags. If you serve the xhtml page
improperly as html, these // are javascript comment tags which mean
that the CData tags are not seen. However if the xhtml page is
properly served as application/xhtml+xml, the browser sees right
through the // to find the CDATA tags and understands what such xml
tags mean. This is fortunate, because most xhtml pages are mis-served
as html rather than application/xhtml+xml. If you have the bare CDATA
tags without // on an xhtml page so mis-served the script will not
work, since a parser for html does not know what they mean.
If you serve an xhtml correctly as application/xhtml+xml, the page can
not be viewed by any IE browser, and will have to resort to some
tricks to get a html page to IE browsers. Most other modern browsers
understand properly served xhtml. I would guess that well over 90% of
pages written in xhtml are not being served as application/xhtml+xml.
In that case the xhtml code serves no useful purpose over html, and
the page would be better written in html 4.01 strict.

 

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

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