...

View Full Version : Replacing div contents in IE from hidden IFRAME



asharma
11-09-2004, 06:54 PM
Hi -

Sorry - I'm probably being very thick here, but I just don't seem to be able to get IE (version 6) to remove child nodes of a div and replace it with a div from some content in a hidden iframe.

It seems to work perfectly well in Firefox version 1.0 and I was hoping someone out there may be able to help.

I have the following code:

<html>
<head>
<title>Test - Create an iframe</title>

<script language="Javascript" type="text/javascript">

document.domain='london.edu';

function makeFrame() {

notesFrame = document.getElementById('remotecontent');

notesFrame.setAttribute("src", "http://forum.london.edu/lbsbiogs_redesign.nsf/httpBiographySearch?SearchView&Query=FIELD+SubjectArea=Accounting");
notesFrame.setAttribute("style", "width: 200px; height: 200px; frameborder: 0px;");

contentdiv = document.getElementById('content');

contentdiv.appendChild(notesFrame);


}


function loaded() {

iframecontent = document.getElementById("remotecontent");

if(iframecontent.contentDocument != null) {

alert("found iframe content");
documentcontent = iframecontent.contentDocument;

documentdiv = documentcontent.getElementById('dominocontent');
if(documentdiv != null) {
alert(documentdiv);

contentdiv = document.getElementById('content');
alert(contentdiv);

contentdiv.appendChild(documentdiv);
contentdiv.removeChild('remotecontent');
}
}
}

</script>
</head>
<body>
<a href="#" onMouseDown="makeFrame()">Click to make iframe</a>
<div id="content">
</div>
<iframe id="remotecontent" name="remotecontent" width="200px" height="200px" frameborder="0px" onLoad="loaded()">
</iframe>
</body>
</html>

This is simply a test file to get working what I need to get working.

To summarise, I do the following:

- grab the iframe remotecontent
- set the src and display properties
- attach the iframe to the parent div (so it can be located in the document tree)

Once the frame loads, the onload event calls loaded() which:

- grabs the iframe
- gets the dominocontent node (which is the one I want to copy)
- grabs a reference to the content div which will be the content's parent
- removes the iframe

This seems to work fine in Firefox (apart from removing the iframe at the very end) but won't work in IE.

Can anyone tell me where I am going wrong?

I'm actually more used to server side development and niavely expected IE to obey the DOM standard!

Willy Duitt
11-09-2004, 07:46 PM
Hi -
....and niavely expected IE to obey the DOM standard!

Don't jump on the IE bashing band wagon to quick...
(besides, I checked this with Firefox also and it does nothing but initially load an empty iframe without a source but nothing suggests that your script recognizes the source code of the iframe... It only recognizes it is there on the page)

There is nothing in your codes that suggest the use of the DOM to retrieve the iframes source... Where's the reference to any nodes? tags?

All I see is references to several elements ( division, iframe) and in the context you are using them you are referencing them as objects... Not what they contain....

.....Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum