Jump to content

Archived

This topic is now archived and is closed to further replies.

Hokus

dynamic frames

Recommended Posts

Hello,

I'm trying to create multiple iFrames with javascript to do some serverside stuff in the background. when I want to dynamically create a 2nd or 3rd iframe within a div, i have to "reload" the contents of the div, which means ALL the iframes will refresh ... so, is there a way to dynamically insert an iframe outside of a tag?

this is what i'm using:

function numForms()
{
str = document.getElementById('numForm').innerHTML
document.getElementById('numForm').innerHTML = str + '<iframe class=\"hideFrame\" src=\"iframe.php\">';
}

I need the previously generated iframes NOT to refresh when I dynamically add another.

Hope it makes sense .. just started playing around with JS.

Thanks!

Share this post


Link to post
Share on other sites
hi,
You can use standard DOM methods for adding elements into the page. I feel, using innerHTML shouldn't be a preferred way. Instead, use
document.createElement(IFRAME) and document.divname.appendChild(varname).
For eg. to add a iframe dynamically in a page on a button click, see following function. To the function I am passing the id of the div to which the frame will be appended.

function addIFrame(divid) {
var newiframe=document.createElement(IFRAME); //IFRAME without quotes
newiframe.id="iframe1";
newiframe.src="http://www.google.co.in"; //replcace as required
div1=document.getElementById(divid);
div1.appendChild(newiframe);
}


Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.