473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Iframe dynamic create and populate immediately

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", "");
ifrm.style.width.value = width+"px";
ifrm.style.height.value = height+"px";
document.body.appendChild(ifrm);
}

function main() {
doTheIframe('smallframe',100,100);

document.getElementById('smallframe').contentWindo w.document.body.innerHTML=
"TEST";
}

<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?

Regards,
Templar


Jul 20 '05 #1
2 47281


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.

<html>
<head>
<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'))) {
iframe.name = iframe.id = iframeName;
iframe.width = width;
iframe.height = height;
iframe.src = 'about:blank';
document.body.appendChild(iframe);
}
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[iframe.name]) {
iframeDoc = window.frames[iframe.name].document;
}
if (iframeDoc) {
iframeDoc.open();
iframeDoc.write(
'<html><body><p>Kibology for all.<\/p><\/body><\/html>');
iframeDoc.close();
}
}
}

window.onload = function (evt) {
test();
}
</script>
</head>
<body>
<h1>Iframe creation test</h1>
</body>
</html>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
oh my goodness!! it works!!
Thanks a million!

But how?

Regards,
Templar
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Scott Nichols | last post by:
Hello, I have an asp.net application. The application dynamically creates an invoice. It is important to see and approve the invoice before it is updated in the database. So...I was...
3
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a...
3
by: Blue Streak | last post by:
Hello, Folks! I am trying to create dynamic content for an IFrame object within an ASPX page. I did not want to try and pull its content from another page. Previously in ASP.Classic I would use...
6
by: paul | last post by:
HI! How do we send a variable from an Iframe page back to its parent? I have a script that calculates the iframe's window size but I need to know how to send that value back to its parent so I...
9
by: Jimbo | last post by:
Hello, I have a user request to build a form in an Access database where the user can check off specific fields to pull in a query. For example, let's say I have 10 fields in a table. The user...
1
by: acemtp | last post by:
Hello, Do you know a dynamic way to send 10kb of text or more using an iframe? I tried to do that with by creating, in javascript, a dynamic iframe, then create a form into this iframe and put...
1
by: jaktharkhan | last post by:
Hi, I really really need help in trying to figure out how can I do a CloneNode on an Iframe where the cloned IFRAME clones with all its contents?. Basically what I am doing is dynamically building...
1
by: redbaks | last post by:
Hi! I am trying to implement adding widgets to our template editor (for blogs). I am worried that i might open a window for XSS attacks so i decided to enveloped all widgets inside an iframe. ...
3
polymorphic
by: polymorphic | last post by:
I have succeeded in embedding PDF files in a dynamic iframe. The problem is that I need the PDF to cache. If the PDF remains the same from page load to page load then the pdf is somehow cached with...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.