Adding content to an iframe

Is it possible to add code or text an iframe after it loads it source? For example, in an IFrame I load some content that lists the numbers 1 - 9. After it loads I want a button on the parent of the iframe that will insert the number 10 into the iframe. Anyone know if this is possible?

Hi,
This shouldn’t be possible due to the security model imposed by browsers (e.g. you could do nasty things, like load up their banks website full-screen and insert highjacking code into it… very bad things).

What you could do instead is to use a JavaScript xmlHttpRequest object to fetch the page and put it’s contents into a scrolling div. This way you can easily perform the modifications required. (Just remember though, the you can only retrieve pages that are on your own site).

For some quick reading, have a look at the following sites:
http://jibbering.com/2002/4/httprequest.html (most straight-forward example)
http://www.webpasties.com/xmlHttpRequest/ (more complex form processing)

Tis possible to change an IFRAME document from same domain without xmlHttpRequest

V Simple Example

The parent page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
  <title></title>
<script language="JavaScript" type="text/javascript">
<!--

function IFAdd(){
 ifobj=window.frames.fred;
 txt=ifobj.document.createTextNode('I am some new text');
 ifobj.document.getElementsByTagName('BODY')[0].appendChild(txt);
}
//-->
</script></head>

<body>
<iframe name="fred" src="IF1.htm" width="400" height="300" frameborder="0"></iframe>
<br>
<input type="button" name="" value="Add to IFRAME" onclick="IFAdd();" >
</body>

</html>

the IFRAME page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
  <title></title>
</head>

<body>
Some Text<br>
</body>

</html>

once IFRAME object is available normal DOM techniques apply using that object