473,320 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Transfer javascript code from iFrame to a DIV

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

Apr 28 '06 #1
4 5916
sa******@gmail.com wrote:
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
--
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)
Apr 29 '06 #2

sa******@gmail.com wrote:
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 );

Apr 29 '06 #3
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);
}
--
Rob
Apr 29 '06 #4
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

Apr 29 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Keith Patrick | last post by:
I have an app where a Shockwave splash animation starts off my app and then sets its parent iframe's src to the value of a default page "BasicReports". BasicReports has a link to another report...
8
by: p3t3r | last post by:
I am using .NET2 and have a number of aspx pages. On each page is a LinkButton that performs a server.transfer() to another page. If we use page names A,B,C,D,E as an example. I start on page A...
5
by: Tudor Tihan | last post by:
Hi, This is my first post here, so please be kind. I have tryed to make a javascript html page loader by using an invisible <IFrame> and some javascript variable text passing between...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
18
by: Chris Ianson | last post by:
Hi geniuses (or is that genii, or genies) The challenge is as above really. I have a page with an iframe in it, and need to call a JS function in the *parent* page, *from* inside the iframe. ...
15
by: Phlip | last post by:
Javascripters: I have an outer page and an inner iframe. The outer page calculates some javascript, and wants the inner frame to run it. The inner frame should hit a page on the same (private)...
5
by: brad | last post by:
I'll post my code below. My goal is to grab the selected text in an iFrame from javascript (really any way possible). When I highlight text in the iFrame and click the link outside of the iFrame, I...
9
by: gwong123 | last post by:
Hey, I need to convert this javascript code into iframe. The javascript goes into a server and brings out an ad banner. The X's is the server IP. <script language="javascript"...
0
by: johnw182 | last post by:
Ok, I have a asp.net project. Everything works great. HOWEVER, this project was made to be called from within a frame or iframe. When being used within the iframe the user gets a blank frame when...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.