Get contents of iframe

Posted on 2006-04-20
Last Modified: 2010-04-09

I just want to get the contents of an iframe on my page. My iframe is defined like:

    <iframe id = "e_body" name = "e_body" src="about:blank"></iframe>

Now I have a function where I want to get the inner contents of the frame, whatever the user has typed in there:

function GetIFrameContentsPlease()
    var strContents = document.getElementById("e_body").document.body.innerHTML;

    alert("the contents are: " + strContents);

But getting the content always fails, how can I get it?
Question by:minnirok
    LVL 7

    Expert Comment

    LVL 7

    Accepted Solution

    getElementById method:

    LVL 8

    Expert Comment

    Because of security concerns, you cannot get the innerHTML cross domain (without appropriate priviledges).
    LVL 7

    Author Comment

    yes finally it works!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
    In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
    In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

    758 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

    10 Experts available now in Live!

    Get 1:1 Help Now