Hokus Posted August 31, 2006 Share Posted August 31, 2006 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').innerHTMLdocument.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! Quote Link to comment Share on other sites More sharing options...
expertsystems Posted September 1, 2006 Share Posted September 1, 2006 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 quotesnewiframe.id="iframe1";newiframe.src="http://www.google.co.in"; //replcace as requireddiv1=document.getElementById(divid);div1.appendChild(newiframe);} Quote Link to comment Share on other sites More sharing options...
Hokus Posted September 2, 2006 Author Share Posted September 2, 2006 thank you, just what i was looking for. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.