[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

innerHTML solution for FireFox

Posted on 2006-04-10
4
Medium Priority
?
1,480 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:HometownComp
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
nabsol earned 2000 total points
ID: 16420232
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
 
LVL 9

Expert Comment

by:smaccari
ID: 16422353
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
 
LVL 4

Expert Comment

by:ysre
ID: 16429737
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
 
LVL 4

Expert Comment

by:ysre
ID: 16431425
BTW nabsol:
But your code doesn't work for Opera 6.x :P
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question