Transfer javascript code from iFrame to a DIV

S

sameergn

Hi,

I have HTML form whose target is an invisible IFrame. After the IFrame
is loaded completely,
following code transfers contents of IFrame to DIV

document.getElementById("mainDiv").innerHTML =
test_iframe.document.body.innerHTML;

but this does not seem to carry over the Javascript code from IFrame to
DIV.
Can anyone comment if this is the correct behavior or a bug?
(The requirement is to submit a form and update only portion of screen,
without using
AJAX. A DIV cannot be target of the FORM, hence the IFrame->DIV route)

Thanks,
Sameer
 
T

Thomas 'PointedEars' Lahn

I have HTML form whose target is an invisible IFrame. After the IFrame
is loaded completely, following code transfers contents of IFrame to DIV

document.getElementById("mainDiv").innerHTML =
test_iframe.document.body.innerHTML;

but this does not seem to carry over the Javascript code from IFrame to
DIV. Can anyone comment if this is the correct behavior or a bug?

`innerHTML' is a proprietary feature, so everything regarding it can be
considered correct behavior, even bugs.
(The requirement is to submit a form and update only portion of screen,
without using AJAX. A DIV cannot be target of the FORM, hence the
IFrame->DIV route)

This is utter nonsense. Simply make the IFrame visible in the first
place, and use CSS to style it.


PointedEars
 
B

bobzimuta

Hi,

I have HTML form whose target is an invisible IFrame. After the IFrame
is loaded completely,
following code transfers contents of IFrame to DIV

document.getElementById("mainDiv").innerHTML =
test_iframe.document.body.innerHTML;

but this does not seem to carry over the Javascript code from IFrame to
DIV.
Can anyone comment if this is the correct behavior or a bug?
(The requirement is to submit a form and update only portion of screen,
without using
AJAX. A DIV cannot be target of the FORM, hence the IFrame->DIV route)

Thanks,
Sameer

Is the javascript inside the body of the IFRAME? To copy the contents
completely as they are, I would use
var content = test_iframe.document.body.cloneNode( true );
document.getElementById("mainDiv").appendChild( content );
 
R

RobG

bobzimuta wrote:
[...]
Is the javascript inside the body of the IFRAME? To copy the contents
completely as they are, I would use
var content = test_iframe.document.body.cloneNode( true );
document.getElementById("mainDiv").appendChild( content );

But 'content' will be a body element, putting a body element inside a
div may have serious implications. You should probably loop through the
child nodes of 'content' and add them to the div one by one:


var content = test_iframe.document.body.cloneNode( true );
var div = document.getElementById("mainDiv");

while (content.firstChild) {
div.appendChild(content.firstChild);
}
 
S

sameergn

Thanks all of you for your replies.
Our architect suggested a simple solution. We added following code in
the JSP that loads in the IFrame

<script language="javascript">
AddUserController = function() {
this.validate = function(formObj) {
// validation code
}
}
window.parent.document.addUserController = new AddUserController()
;
</script>

This add a Javascript object called addUserController in the parent
document and then
The code loaded in IFrame can use addUserController to call functions
like validate().

<script language="javascript">
window.parent.getIFrameData();
</script>

getIFrameData() is defined in parent document.
function getIFrameData()
{
document.getElementById("mainDiv").innerHTML =
test_iframe.document.body.innerHTML;
} // getIFrameData().

We initially were using DWR, but it allows accessing only POJOs
through AJAX and
we wanted to call just the JSP. We found that DWR uses same IFrame
mechanism
if posting method is IFrame instead of XMLHttpRequest (but still posts
to POJO).
Is there any recommended,well tested AJAX library that can be used
here to post to
any URLs?

Thanks,
Sameer
 

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,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top