PDA

View Full Version : Inserting content in an iframe's div



Lleoun
Nov 25th, 2009, 07:15 PM
Hi all,

I have:


var moreinfo ="";
moreinfo+= "here some content";
$("#divMoreInfo").html(moreinfo);


And this inserts "here some content" in a div called divMoreInfo.

Now divMoreInfo is placed inside an iframe while the rest of the programming has to be in the parent page... How do I insert moreinfo's contents in the iframe's div??

Thanks a lot

Lleoun
Nov 26th, 2009, 10:48 AM
I've tried:

window.frames["iframeName"].document.getElementById("divMoreInfo").innerHTML(moreinfo);
but I get a "is null" error :(

Ok, would it be easier to get rid of the div inside of the page contained by the iframe??
Let's say I have parent page with the programming and the iframe and I want to write:

var moreinfo ="";
moreinfo+= "here some content";
moreinfo inside of the contained page, no divs no anything else.. is that a better choice ?? How can that be done?

Thanks once again

drb
Nov 26th, 2009, 04:19 PM
If I'm reading it correctly, you want to build the the string "moreinfo" in javascript, and then write it to a a div in the body of the HTML, no?

This is one way you could go about it, using a div with ID "exampleDiv" for demonstration:


<html>
<head>
<script type='text/javascript'>
function writeMoreInfo()
{
var moreinfo="";
moreinfo+="here some content";
with(document.getElementById('exampleDiv')){
open();
write(moreinfo);
close();
}
}
</script>
</head>
<body onload="writeMoreInfo();">
<div id='exampleDiv'></div>
</body>
</html>


I used a basic HTML document for the sake of simplicity obviously. Apologies if I've misunderstood what you're trying to do.

Kor
Nov 26th, 2009, 04:20 PM
Give your iframe an id , say: id="iframeID"


document.getElementById('iframeID').contentWindow.document.getElementById('divMoreInfo').innerHTML=m oreinfo;