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! Link to comment https://forums.phpfreaks.com/topic/19233-dynamic-frames/ 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);} Link to comment https://forums.phpfreaks.com/topic/19233-dynamic-frames/#findComment-83900 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. Link to comment https://forums.phpfreaks.com/topic/19233-dynamic-frames/#findComment-84446 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.