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

2 Responses to “bug in FireFox?”

  1. Twey Says:

    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 “&ltgrom&gtQuux” 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 &lt; and &gt; exist: <pre> is not automatically CDATA.

  2. Anonymous Says:

    So do you think if we do CDATA it should be ok?

Leave a Reply