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)
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>
Updated•20 years ago
|
Assignee: nobody → general
Component: General → DOM
Product: Firefox → Core
QA Contact: general → ian
Version: unspecified → Trunk
Updated•20 years ago
|
Component: DOM → DOM: Core
Comment 1•19 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
Comment 2•19 years ago
|
||
Please attach a testcase showing the problem.
Comment 3•19 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•19 years ago
|
||
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.
Comment 5•19 years ago
|
||
That works just fine. Does it work without the setTimeout?
Comment 6•19 years ago
|
||
That does not work. Again, should it really work? (Probably for backcompat...)
Comment 7•19 years ago
|
||
Bug 207842 is for the timeout issue
Comment 8•19 years ago
|
||
> 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•18 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
Comment 10•18 years ago
|
||
> 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
You need to log in
before you can comment on or make changes to this bug.
Description
•