View Full Version : Data inside an iframe and a span

12-19-2007, 02:21 AM
ok, so i have this html with this code in the body

<div id = "info">blahblahblah</div>
<span id = "iframespan"><iframe src="page.php" name="iframepage" id="iframe"></iframe></span>

and inside the page.php

<div id="outer>
<div id="content">
blah blah blah

so i want it that when it loads, the content of "info" is transferred to the content of "content". Please help.

12-20-2007, 12:42 AM

12-21-2007, 09:17 AM
In the page.php you can add the following code in your client-side script tags.

window.onload = function(){
document.getElementById('content').innerHTML = parent.window.document.getElementById('info').innerHTML;

The above code will trigger as the load event of your iframe window. Hope this help

12-23-2007, 12:14 AM
uhmm.. thanks! how do you do it reversely? from the parent document?

12-23-2007, 10:50 AM
The reverse way may not work on all browsers correctly due to some security restrictions but as you can see above, you simply change the "getter" and "setter" elements like below:

parent.window.document.getElementById('info').innerHTML = document.getElementById('content').innerHTML;

01-02-2008, 08:15 PM
uhmm.. thanks! how do you do it reversely? from the parent document?
I think that :

var iframeObj = document.getElementById('iframe');
var temp = '';
if (iframeObj.contentDocument)
temp = iframeObj.contentDocument.getElementById('content').innerHTML;
else if(iframeObj.contentWindow)
temp = iframeObj.contentWindow.document.getElementById('content').innerHTML;
else if(iframeObj.document)
temp = iframeObj.document.getElementById('content').innerHTML;
document.getElementById('info').innerHTML = temp;