bug in FireFox?
Look at the following code.
<html>
<head><title>Bug in Mozilla?</title></head>
<script type="text/javascript">
function AlertAll(tagname)
{
var arr=document.getElementsByTagName(tagname);
for(i=0;i<arr.length;i++)
{
code=arr[i].innerHTML;
alert(code);
}
}
</script>
<body>
<pre id="python">
print "Hello";
</pre>
<pre id="php">
<?php
printf("Hello");
?>
</pre>
<script type="text/javascript">
AlertAll("pre");
</script>
</body>
</html>
It fails in mozilla, but works in IE. Looks like innerHTML when you have text pattern like <? it fails.
click here for the live version.
The second messagebox will be empty in FireFox. It works good in IE 6 and 7
February 22nd, 2007 at 1:55 pm
This isn’t a bug. The HTTP specification says that when a browser sees a tag it doesn’t recognise, it should ignore it; E.G. “<flurb>Wibble</flurb>” becomes “Wibble” and “<grom>Quux” becomes “Quux”. Any sane HTML parser will see “<?php blah blah blah ?>” as one single unrecognised tag, and remove it from the parse tree.
This is why < and > exist: <pre> is not automatically CDATA.
February 24th, 2007 at 1:24 am
So do you think if we do CDATA it should be ok?