Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / April 2006



Tip: Looking for answers? Try searching our database.

Transfer javascript code from iFrame to a DIV

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sameergn@gmail.com - 28 Apr 2006 20:52 GMT
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
Thomas 'PointedEars' Lahn - 29 Apr 2006 00:48 GMT
> 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;

<URL:http://pointedears.de/scripts/test/whatami#inference>

> 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
Signature

A man who works with his hands is a laborer; a man who works with his
hands and his brain is a craftsman; but a man who works with his hands
and his brain and his heart is an artist.
 -- Louis Nizer, lawyer (1902-1994)

bobzimuta - 29 Apr 2006 00:50 GMT
> Hi,
>
[quoted text clipped - 14 lines]
> 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 );
RobG - 29 Apr 2006 13:04 GMT
[...]

> 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);
  }

Signature

Rob

sameergn@gmail.com - 29 Apr 2006 20:02 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.