Jump to content

dynamic frames


Hokus

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!
Link to comment
https://forums.phpfreaks.com/topic/19233-dynamic-frames/
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);
}


Link to comment
https://forums.phpfreaks.com/topic/19233-dynamic-frames/#findComment-83900
Share on other sites

Archived

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

×
×
  • Create New...

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.