PDA

View Full Version : Help me fix my validation errors.


SledgeHammer
2007-04-01, 10:06
When I run my website through the W3C's HTML validator, I get 3 errors. They are all the same error, and I think I know why they are occurring, but I don't know if I can fix them.

The error is "document type does not allow element "img" here." All three instances of the error occur in the section below:

<script language="javascript" type="text/javascript">


if (navigator.appName != "Microsoft Internet Explorer")
{document.write("<img src='images/homeheadtop.gif' alt='Frodos Notebook' height='126' width='630' /> <img src='images/headtail.gif' alt=' ' class='head' />")}

if (navigator.appName == "Microsoft Internet Explorer")
{document.write("<img src='images/iehead.gif' alt='Frodos Notebook' width='630' />")}


</script>


I assume the problem comes from the tags being inside the script, but I was hoping there was a way I could keep the functionality and still get the site to validate.

The site in question. (http://www.frodosnotebook.com)
The validator results page. (http://validator.w3.org/check?uri=http%3A%2F%2Fwww.frodosnotebook.com%2F&charset=%28detect+automatically%29&doctype=Inline)

Brad
2007-04-01, 14:33
You need CDATA!

Try this:


<script language="javascript" type="text/javascript">
//<![CDATA[

if (navigator.appName != "Microsoft Internet Explorer")
{document.write("<img src='images/homeheadtop.gif' alt='Frodos Notebook' height='126' width='630' /> <img src='images/headtail.gif' alt=' ' class='head' />")}

if (navigator.appName == "Microsoft Internet Explorer")
{document.write("<img src='images/iehead.gif' alt='Frodos Notebook' width='630' />")}

//]]>
</script>

SledgeHammer
2007-04-03, 13:46
That did the trick. Thanks!

drewprops
2007-04-05, 17:36
About two years ago I built something on my site that would go and scrape new stories from the pages of other sites... maybe from their feeds, can't remember. Looking back, it was pretty cool... if not more than a little wrong, though I wasn't doing any SEO stuff and gave direct links to THEIR websites... did it using CDATA somehow, for the life of me I can't remember how, now. I only learn to code for specific tasks then forget it. Repetition makes Johnny a good coder.

Brad
2007-04-05, 18:01
CDATA simply tells parsers to ignore the contents. For example, any < or & characters in the CDATA block will not trigger the start of a tag or character entity.

drewprops
2013-11-25, 16:57
Bump. I just remembered the scraping thing again just now, and how some people at a website called "Core77" emailed me to ask how I did it. I think it was a jury-rigged version of what we now call a feed... I was copying the links and the headlines and cooking it down into a "stolen feed" from their website (so I wasn't actually stealing their content). The Core77 code person was interested in the technique.

I just felt like Forrest Gump.



...