PDA

View Full Version : Data inside an iframe and a span



lordjeremiahs
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


<script>
?????
</script>
<div id="outer>
<div id="content">
blah blah blah
</div>
</div>

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

lordjeremiahs
12-20-2007, 12:42 AM
bump.

codeexploiter
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

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

BYK
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;

bb3333bb
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;