Closed Bug 297685 Opened 20 years ago Closed 18 years ago

DOM-created iframe can't insert content via appendChild

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: freitaka, Unassigned)

Details

(Keywords: testcase, Whiteboard: WFM)

Attachments

(2 files)

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>
Assignee: nobody → general
Component: General → DOM
Product: Firefox → Core
QA Contact: general → ian
Version: unspecified → Trunk
Component: DOM → DOM: Core
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.
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.
Attached file 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.
Keywords: testcase
That works just fine. Does it work without the setTimeout?
That does not work. Again, should it really work? (Probably for backcompat...)
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.
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
Closed: 18 years ago
Resolution: --- → WONTFIX
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.

Attachment

General

Creator:
Created:
Updated:
Size: