Official ObjectGraph Blog
Saturday, January 20, 2007
bug in FireFox?
Look at the following code.
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
<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>
click here for the live version.
The second messagebox will be empty in FireFox. It works good in IE 6 and 7
posted by gavi at 11:03 AM
2 Comments:
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.
By Anonymous, at 8:55 AM
So do you think if we do CDATA it should be ok?
By Anonymous, at 8:24 PM
Post a Comment
<< Home