Get contents of iframe

Hi,

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?
LVL 7
minnirokAsked:
Who is Participating?
 
bubbledragonCommented:
getElementById method:

document.getElementById('e_body').contentWindow.document.body.innerHTML;
0
 
bubbledragonCommented:
document.frames("e_body").document.body.innerHTML;
0
 
KennyTMCommented:
Because of security concerns, you cannot get the innerHTML cross domain (without appropriate priviledges).
0
 
minnirokAuthor Commented:
yes finally it works!
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.