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

Discussion in 'HTML' started by meyazoo@gmail.com, Aug 28, 2007.

  1. Guest

    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>
     
    , Aug 28, 2007
    #1
    1. Advertising

  2. Martin Jay Guest

    On Tue, 28 Aug 2007 00:07:27 -0000, 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?


    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.
    --
    Martin Jay
     
    Martin Jay, Aug 28, 2007
    #2
    1. Advertising

  3. cwdjrxyz Guest

    On Aug 27, 7:07 pm, 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.
     
    cwdjrxyz, Aug 28, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. thunk
    Replies:
    0
    Views:
    537
    thunk
    Apr 1, 2010
  2. thunk
    Replies:
    14
    Views:
    662
    thunk
    Apr 3, 2010
  3. Sergio del Amo Caballero

    xhtml 1.0 strict with javascript

    Sergio del Amo Caballero, Oct 15, 2003, in forum: Javascript
    Replies:
    5
    Views:
    177
    Richard Hockey
    Oct 15, 2003
  4. Jonny

    Javascript with XHTML 1.0 strict?

    Jonny, Jan 23, 2004, in forum: Javascript
    Replies:
    6
    Views:
    165
    Martin Honnen
    Jan 23, 2004
  5. Paul Marsh
    Replies:
    7
    Views:
    147
    cwdjr
    Sep 19, 2004
Loading...

Share This Page