Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Iframe dynamic create and populate immediately

Thread Tools

Iframe dynamic create and populate immediately

Posts: n/a
Hi i'm bothering with such problem... I must dynamic create an Iframe, and
then put som raw HTML into it. But I can't.

When I create iframe, I can't access its properties.

Here's the coe snipplet:


function doTheIframe(nazwa, width, height) {
ifrm = document.createElement("iframe");
ifrm.setAttribute("name", nazwa);
ifrm.setAttribute("id", nazwa);
ifrm.setAttribute("src", ""); = width+"px"; = height+"px";

function main() {

document.getElementById('smallframe').contentWindo w.document.body.innerHTML=

<a onclick="main()">Tratatata</a>


When I click the link, iframe is created but not pupulated.
When I click for the second time, second frame is created and the first one
is populated.

I want to populate the iframe immediately.
How to do this?


Reply With Quote
Martin Honnen
Posts: n/a

Templar wrote:

> Hi i'm bothering with such problem... I must dynamic create an Iframe, and
> then put som raw HTML into it. But I can't.

The following works for me with Netscape 7.1, IE6. Should work with
Netscape 6/7 and IE5/5.5 too.
I can't get it to work with Opera but I think I have filed a bug on that
some while ago. You might want to try to load a dummy HTML page first to
be able to script the document for Opera.

<title>creating an iframe element and document.writing content to the
iframe window</title>
<script type="text/javascript">
function createIframe (iframeName, width, height) {
var iframe;
if (document.createElement && (iframe =
document.createElement('iframe'))) { = = iframeName;
iframe.width = width;
iframe.height = height;
iframe.src = 'about:blank';
return iframe;

function test () {
var iframe = createIframe ('iframe0', 300, 300);
if (iframe) {
var iframeDoc;
if (iframe.contentDocument) {
iframeDoc = iframe.contentDocument;
else if (iframe.contentWindow) {
iframeDoc = iframe.contentWindow.document;
else if (window.frames[]) {
iframeDoc = window.frames[].document;
if (iframeDoc) {;
'<html><body><p>Kibology for all.<\/p><\/body><\/html>');

window.onload = function (evt) {
<h1>Iframe creation test</h1>

Martin Honnen

Reply With Quote
Posts: n/a
oh my goodness!! it works!!
Thanks a million!

But how?


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to populate iframe when click on subba_reddy ASP .Net 2 06-22-2006 12:00 PM
Populate a popup window with clickable records from an Access DB and upon clicking, populate a selectbox on the original webpage with the clicked record Enjoy Life ASP General 2 02-23-2005 10:48 PM
How would I create the following XML file and populate withdata from a dataset? Ray Stevens ASP .Net 1 12-28-2004 07:11 PM
jsp populate a listbox without blocking the user (iframe?) vulkanino Java 0 12-16-2004 12:13 PM
Get form values from iframe (1) to iframe (2) inside a layer in iframe (1) Daedalous Javascript 3 01-16-2004 11:08 AM