DOM-created iframe can't insert content via appendChild

RESOLVED WONTFIX

Status

()

Core
DOM: Core & HTML
RESOLVED WONTFIX
13 years ago
a year ago

People

(Reporter: Kevin Freitas, Unassigned)

Tracking

({testcase})

Trunk
x86
Windows XP
testcase
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: WFM)

Attachments

(2 attachments)

(Reporter)

Description

13 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.
iframeBody.style.background).

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:

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

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

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

<body onload="iframeFun();">

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

</body>
</html>

Updated

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

Updated

13 years ago
Component: DOM → DOM: Core

Comment 1

12 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

12 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

12 years ago
Created attachment 197357 [details]
testcase

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
cetera.

Updated

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

Comment 6

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

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

Comment 7

12 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

11 years ago
Hi!

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: www.dwergpapegaai.com

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: http://www.dwergpapegaai.com/functions.js

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.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 11 years ago
Resolution: --- → WONTFIX

Updated

9 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.