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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.