how to appendChild to iframes

D

Dmitry Kulinich

var iframe = document.createElement("<IFRAME id='frame0' style='PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px' border='no' name='frame0' src='RasteriserServlet?width=200&amp;height=200&amp;bgColor=#FFFFFF&amp;fgColor=#000000' frameBorder='no' width='200' scrolling='no' height='200' menuId='formControlPopup' childName='frame' showLable='true' labelPosition='bottom'>");

var form = document.createElement("<FORM action='RasteriserServlet?' name='form0' childName='form' method='Post' id='form0'>");


iframe.appendChild(form);

or

iframe.insertBefore(form);
doesn't works "Unexpected call to method or property access."

So,
how to appendChild to iframes?
 
D

Darko

var iframe = document.createElement("<IFRAME id='frame0' style='PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px' border='no' name='frame0' src='RasteriserServlet?width=200&amp;height=200&amp;bgColor=#FFFFFF&amp;fgColor=#000000' frameBorder='no' width='200' scrolling='no' height='200' menuId='formControlPopup' childName='frame' showLable='true' labelPosition='bottom'>");

var form = document.createElement("<FORM action='RasteriserServlet?' name='form0' childName='form' method='Post' id='form0'>");

iframe.appendChild(form);

or

iframe.insertBefore(form);
doesn't works "Unexpected call to method or property access."

So,
how to appendChild to iframes?

Several issues:
To my knowledge, you can't create elements with

var td = document.createElement( "<td id='bla' width='100%'>" );

but with

var td = document.createElement( "td" );
td.setAttribute( "id", "bla" );
td.setAttribute( "width", "100%" );
etc.

Now, I used TD as an illustration, it should of course refer to the
iframes as well. Maybe there's some part of DOM that parses the
strings in the fashion you used them, but I'm not familiar with that.

Second, iframes are actually a form of windows, not DOM nodes, that in
themselves container documentElement and documentElement in its self
contains Elements. So, what you should do is find the iframe's
contentWindow, then its document element, and then you can find the
'body' element of the document; then you can append children to the
latter.

So, what you should probably do is something like this: (not tested,
but just pointing the direction)

var iframe = document.createElement("IFRAME" );
iframe.id = 'frame0';
iframe.setAttribute( "style", 'PADDING-RIGHT: 0px; PADDING-LEFT: 0px;
PADDING-BOTTOM: 0px; PADDING-TOP: 0px'" );
iframe.setAttribute( "border, 'no' );
iframe.setAttribute( "name", 'frame0' );
iframe.setAttribute( "src", 'RasteriserServlet?
width=200&amp;height=200&amp;bgColor=#FFFFFF&amp;fgColor=#000000' );
iframe.setAttribute( "frameBorder", 'no' );
.....

var form = document.createElement( "FORM" );
form.setAttribute( "action", 'RasteriserServlet?' );
form.setAttribute( "name", 'form0' );
.....

iframe.contentWindow.document.body.appendChild( form );

I don't know if this is going to work though, cause just creating the
"iframe" element shouldn't create all of its necessary children I
named above, such as contentWindow, its corresponding document, body,
etc. elements.
So, maybe, the thing you're doing maybe isn't the best idea in the
very root of its concept?
 
D

Dmitry Kulinich

Thanks a lot, it is was really nice to read.
Unfortunately, I need to append form as child to iframe node, NOT in frame
document. After initialization with values needed (form contains a lot of
hidden inputs) this form is really added in iframe document (pseudo Ajax)
but it is clear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,335
Latest member
Tommiesal

Latest Threads

Top