innerHTML solution for FireFox

In the IE6 I can use Javascript to get the innerHTML   ie       "something".innerHTML

But in Firefox nothing is returned.  What javascript will return the innerHTML or the HTML of the entire page for Firefox please?
HometownCompAsked:
Who is Participating?
 
nabsolCommented:
Hi
I think you want HTML of entire page. Check out this code works for both ie6 and firefox. :)

<html id="myhtml">
<script language="JavaScript">
function test()
{
  alert(document.getElementById("myhtml").innerHTML)
}
</script>

<body id="mybody" onload="test()">
<div id="mydiv">
abcdabcd
</div>
</body>
</html>

By Nab
0
 
smaccariCommented:
There is something weird in your title and question, as Firefox does implement the innerHTML property, and it works fine.
Maybe that's because by "something".innerHTML, you mean that if you have an element with id "mydiv", you try to acces its innerHTML by: myDiv.innerHTML
Maybe You should use: document.getElementById("myDiv").innerHTML
(nabsol uses this syntax as you can see though)
0
 
ysreCommented:
According to the DOM model (and eg. firefox keeps complaining vigorously ?? if you don't ;)) you have to get every element via document.getElementBy* (eg. var el = document.getElementById ("myelementid"); if (el) { /* do sth with the element */ } ).

Then you'd just use  el.innerHTML = mynewhtmlforelement;

In case of some mozilla-like browsers not providing the .innerHTML property  get mozInnerHTML.js (google) and add it if you can't find the .innerHTML property, eg. if (!document.body.innerHTML) { document.write ("<SCRI"+"PT language='JavaScript' src='./mozInnerHTML.js'></S"+"CRIPT>"); }

Ys
0
 
ysreCommented:
BTW nabsol:
But your code doesn't work for Opera 6.x :P
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.