Inner HTML in Firefox

Posted on 2006-04-10
Last Modified: 2013-11-19
In the IE6 I can use Javascript to get the innerHTML   ie       element.innerHTML

But in Firefox nothing is returned.  What javascript will return the innerHTML or the HTML of the entire page please?
Question by:HometownComp
    LVL 4

    Accepted Solution

    I think this is what you were after:

    IE method to switch to source view:

    iHTML = getDocument().body.innerHTML;
    getDocument().body.innerText = iHTML;

    Mozilla method to switch to source view:

    var html = document.createTextNode(getDocument().body.innerHTML);
    getDocument().body.innerHTML = "";

    IE method to switch back to regular view:

    iText = getDocument().body.innerText;
    getDocument().body.innerHTML = iText;

    Mozilla method to switch back to regular view:

    var html = getDocument().body.ownerDocument.createRange();
    getDocument().body.innerHTML = html.toString();

    All of which can be found here:
    LVL 2

    Assisted Solution

    This will work fine in both IE and Firefox.
    var bodyElement = document.getElementsByTagName('html')[0].innerHTML;

    Use document.getElementsByTagName('tag name') or document.getElementById('elements id') to access DOM element correctly.

    Featured Post

    Course: HTML5 for Beginning Beginners

    Are you looking for an efficient introduction to HTML5? Have you tried other HTML5 courses and found them too complex? Do you need just the basics of HTML5 to use with Wordpress or other content management system? If you said yes to any of these questions, this course is for you.

    Join & Write a Comment

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now