Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

  1.  permalink
    Re-designing and updating my web-site, I was recently correcting mistakes in W3C validator, as I've stumbled over quite an interesting problem I couldn't solve. I'd like to keep my old javascript-based counter, but the problem is that W3C Validator reports the following error:

    "Document type does not allow element "img" here.
    r+"' width="1" height="1" alt="Counter" />")</script>"

    Javascript code on the page:

    <script type="text/javascript">
    r=""+Math.random()+"&ref="+escape(document.referrer)+"&pg="+escape(window.location.href);
    document.write("<img src='http://www.domain.com/counter.php?id="+r+"' width="1" height="1" alt="Counter" />")</script>

    As I've found out, document.write doesn't work in XHTML (http://www.w3.org/MarkUp/2004/xhtml-faq.html#docwrite). But still, how could I combine both CSS Validity and counter's functionality? Any suggestions, ideas?
  2.  permalink
    Document.write is depercated/won't work in XHTML.

    You need to use createElement, appendChild, and textNode to create the element, and append it to something.
    • CommentAuthorpmullin
    • CommentTimeApr 13th 2006
     permalink
    •  
      CommentAuthornifkin
    • CommentTimeApr 13th 2006 edited
     permalink
    DOM's the way to go. I haven't tried testing this but it should be relatively close..

    <script type="text/javascript">
    /*<![CDATA[*/
    var imgsrc="http://www.domain.com/counter.php?id="+Math.random()+"&amp;ref="+escape(document.referrer)+"&amp;pg="+escape(window.location.href);
    var timg = document.createElement('img');
    timg.setAttribute('src',imgsrc);
    timg.setAttribute('alt','counter');
    var loadtracker=document.getElementById('trackerimage');
    loadtracker.appendChild('timg');
    /*]]>*/
    </script>

    <div id="trackerimage"></div>
    •  
      CommentAuthornifkin
    • CommentTimeApr 13th 2006
     permalink
    Document.write is depercated/won't work in XHTML.

    It will work in any XHTML that's served as text/html (which is still acceptable for XHTML1.0 strict/transitional).
  3.  permalink
    Yes, but at that point, it's not really XHTML. At that point, you're using an XHTML doctype with HTML formatted like XHTML.
    •  
      CommentAuthornifkin
    • CommentTimeApr 13th 2006
     permalink
    Dude, your "XHTML with appropriate mime-type" evangelism is a fine thing. But it's serious overkill for 99.99% of the web right now.
  4.  permalink
    I'm not suggesting that someone actually use XHTML, I'm suggest quite the opposite. What's the point of an XHTML doctype when you're not using XHTML? So you look all spiffy and cool because you're jumping on the XHTML fad bandwagon?

    What's wrong with HTML 4.01? As elements go, it's identical. You can format your HTML just like you would format your XHTML so you can't say XHTML syntax is better.

    I don't understand why someone would need to or want to use XHTML over HTML when they're not using XHTML in any way, shape or form.
    • CommentAuthorKanashii
    • CommentTimeApr 13th 2006
     permalink
    Either way they shouldn't be using document.write ever. It's ugly, obtrusive, and just wrong, just like innerHTML. Follow Nifkins advice on using the DOM.
    •  
      CommentAuthorSpookyET
    • CommentTimeApr 14th 2006
     permalink
    I believe that IE has problems with setAttribute() if I am not mistaken. document.write seems like the way to go for now. That said, 4.01 Strict is fine and dandy, but it's not future safe (:sarcasm:). There is nothing wrong with 4.01 Strict. Absolutely nothing. However, if you want to make the FUDers STFU, you have to use XHTML.
  5.  permalink
    What's wrong with HTML 4.01? As elements go, it's identical. You can format your HTML just like you would format your XHTML so you can't say XHTML syntax is better.

    What's wrong with XHTML 1.0? As elements go, it's identical. You can format your XHTML just like you would format your HTML so you can't say HTML syntax is better.
    •  
      CommentAuthorSpookyET
    • CommentTimeApr 15th 2006
     permalink
    ten safe frongs, he's using XHTML 1.1 or 1.0 as application/xhtml+xml.
    • CommentAuthorNick Presta
    • CommentTimeApr 15th 2006 edited
     permalink
    What's wrong with XHTML 1.0? As elements go, it's identical. You can format your XHTML just like you would format your HTML so you can't say HTML syntax is better.

    When you use text/html, nothing, because they are almost identical. When you use it with application/xhtml+xml, there are bigger problems that getting a counter to work.
    •  
      CommentAuthorSpookyET
    • CommentTimeApr 15th 2006 edited
     permalink
    nick1presta: There are no problems when you use application/xhtml+xml. It's just different. You got to adapt to it.

    SGML and XML (though based on it) are different beasts.
    •  
      CommentAuthorkayloe
    • CommentTimeApr 18th 2006
     permalink
    there is a news entry and a link to a site that provides a neat solution to this problem: http://www.vivabit.com/bollocks/2006/04/06/introducing-dom-builder
Add your comments
    Username Password
  • Format comments as (Help)