DOM-created iframe can't insert content via appendChild




14 years ago
2 years ago


(Reporter: freitaka, Unassigned)



Windows XP

Firefox Tracking Flags

(Not tracked)


(Whiteboard: WFM)


(2 attachments)



14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4

When using JS and the DOM to create and iframe element any further content to be
inserted into the iframe document iself won't work. The DOM inspector shows a
default html and body in the iframe but any new content won't insert unless
triggered by a time delay.

Reproducible: Always

Steps to Reproduce:
1. create and insert an iframe on a page via DOM
2. immediately attempt to create a text or other node and append it inside the
body of the newly created iframe

Actual Results:  
The DOM inspector shows the iframe was successfully created and that basic page
constructs were automatically inserted (a la about:blank). No appended content
is inserted nor can the properties of the iframe's body be altered (e.g.

Expected Results:  
Element, text node and style changes on default elements inside the iframe
should be available for alteration and insertion.

If a setTimeout() trigger is used to delay any desired changes to the iframe's
content things work out just great. See the following working code sample:

    <title>Inserting Content Into a Homemade Iframe</title>
    function iframeFun() {
        var pageBody = document.getElementsByTagName("body")[0];
        var newIframe = document.createElement("iframe");
        newIframe.setAttribute("id", "cool_iframe");

        setTimeout("intoIframe()", 1);
    function intoIframe() {
        var newIframe = document.getElementsByTagName("iframe")[0];

        // create content inside iframe
        var iframeBody = newIframe.contentDocument.getElementsByTagName("body")[0]; = "#0f0";
        var iframeHeading = document.createElement("h4");
        var textHeading = document.createTextNode("This content was inserted via
the DOM");

<body onload="iframeFun();">

<h3>Here's an iframe:</h3>



14 years ago
Assignee: nobody → general
Component: General → DOM
Product: Firefox → Core
QA Contact: general → ian
Version: unspecified → Trunk


14 years ago
Component: DOM → DOM: Core

Comment 1

14 years ago
Can you try again?
Over here, your code WORKSFORME.
I also see the nodeValue of the created text node and the background property
value of the body in the DOM inspector.
Seamonkey 1.0a rv: 1.9a1 build 2005082606 and Deer Park alpha 2 rv: 1.8b4 build
20050826 under XP Pro SP2.

If the code does not work, then please attach it to this bugfile using the
Create a New Attachment. Thanks
Whiteboard: WFM
Please attach a testcase showing the problem.

Comment 3

14 years ago
createElement and createTextNode create the nodes in the document they are
invoked on. You either need to import the nodes into the target document (of the
iframe) or create them using the iframe's document.

Comment 4

14 years ago
Created attachment 197357 [details]

Now per the DOM specification this should not work, but in older Mozilla builds
it does. I'm not sure if it still works with the ownerDocument fixes, et


14 years ago
Keywords: testcase
That works just fine.  Does it work without the setTimeout?

Comment 6

14 years ago
Created attachment 197386 [details]
testcase (without timeouts)

That does not work. Again, should it really work? (Probably for backcompat...)

Comment 7

14 years ago
Bug 207842 is for the timeout issue
> Again, should it really work?

That's the question.  What I suspect is happening is that the default blank
document load (which is asynchronous, of course) happens after you've munged the
DOM and wipes out your changes.

Comment 9

13 years ago

I am experiencing a simular bug!

I am developping a super advanced forum system and run into a firefox bug. Firefox isn't able to use the iframe object when it is moved more then once (the first time it does work!) or when created as new! (document.createElement)

I've spend almost 12 hours in a row today to get this bug fixed and it simply doesn't seem possible because of this Firefox bug.

This is the site on wich I am testing:

You can post a message (wich will work fine), and then try to reply to the message you just posted (message is implemented via AJAX so you can do that directly). It won't work, in IE all possible solutions work fine!

My javascript is here:

So to be short:

document.frames['framename'] DOES NOT work anymore when it's object (the frame) has been moved or "deleted and rebuild" more then 1 time (the first time it does work!!!!).

Please help!

Best Regards,
Jan Jaap Hakvoort
> I am experiencing a simular bug!

If it's not this exact bug, please file a separate bug report on it.  Please make sure to describe the bug clearly, with steps to reproduce (which are missing from comment 9).

The original bug here is either INVALID or WONTFIX.  Picking one.
Last Resolved: 13 years ago
Resolution: --- → WONTFIX


11 years ago
Component: DOM: Core → DOM: Core & HTML
QA Contact: ian → general
You need to log in before you can comment on or make changes to this bug.