get contents of iframe

M

markww

I cannot get the contents of an iframe in my page, it is quickly
driving me insane. My iframe is defined like:

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

I've made a function to retrieve the contents like:

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

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

but it fails. I need this to work on IE and FF, any suggestions?

Thanks
 
N

Neredbojias

I cannot get the contents of an iframe in my page, it is quickly
driving me insane. My iframe is defined like:

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

I've made a function to retrieve the contents like:

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

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

but it fails. I need this to work on IE and FF, any suggestions?

You realize you do need an actual source (-html document) in order to get
the contents of the iframe? I don't know if "about:blank" does it.

With that in mind, try this:

setTimeout("alert(e_body.document.body.innerHTML);",10);
 
M

markww

Hi,

Yes there is no initial content, but the user is allowed to type in the
iframe with designMode = 'on' - I just need to get whatever they have
typed into the iframe. I'll give what you posted a try,

Thanks
 
J

Jonathan N. Little

markww said:
Hi,

Yes there is no initial content, but the user is allowed to type in the
iframe with designMode = 'on' - I just need to get whatever they have
typed into the iframe. I'll give what you posted a try,

Thanks
If I understand you correctly you are using an IFRAME to get user input?
HTML already contains an element for such purpose, it is a FORM with a
TEXTAREA. Why the re-engineering?
 
M

markww

Hi Jonathan,

I wanted to use an iframe so that the user could do some limited rich
text formatting, and I wouldn't have to script anything extra. I would
like there to be a button beneath the iframe such as 'edit' - in which
case the user can start typing in there, make text bold, type weblinks
like www.something.com. Then they could just hit 'stop edit', in which
case I'd just turn design mode 'off' and the weblinks they typed become
active, the rich text maintains its formatting, etc.

All I'd have to do is flip the designMode switch.

Textareas as I understand don't allow for such formatting or clickable
links?

Thanks
 
J

Jonathan N. Little

markww said:
Hi Jonathan,

I wanted to use an iframe so that the user could do some limited rich
text formatting, and I wouldn't have to script anything extra. I would
like there to be a button beneath the iframe such as 'edit' - in which
case the user can start typing in there, make text bold, type weblinks
like www.something.com. Then they could just hit 'stop edit', in which
case I'd just turn design mode 'off' and the weblinks they typed become
active, the rich text maintains its formatting, etc.

Many rich text widgets out there, here is one:

http://dojotoolkit.org/docs/rich_text.html
Rich Text Editing With Dojo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top