xhtml strict javascript problem trying to use "id" in plane of "name" attribute

M

meyazoo

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>
 
M

Martin Jay

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?

The 'id' is fine. The validator doesn't like 'name.'
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[ ?

There's an explanation here: <http://en.wikipedia.org/wiki/CDATA>.

You may find that 'HTML 4.01 strict' is more suited to your needs.
 
C

cwdjrxyz

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.
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top