Problems getting same-domain IFRAME content in FireFox

A

aatcbbtccctc

Hi folks

I've googled for an answer to this, with no success. Can someone please
jump in, and put me out of my misery! (I'm sure it's quite simple)

I have an invisible IFRAME, and a visible DIV:

<IFRAME id=myframe style="display:none" src="..."
onload="ShowNews(this)"></IFRAME>

<DIV id=mydiv></DIV>

I need to copy the content from the IFRAME, into the DIV. Everything
comes from the same domain, so there are definitely not any
cross-domain security issues.

This works fine in IE6:

function ShowNews(x) {
document.all.mydiv.innerHTML =
x.contentWindow.document.body.outerHTML
}

but in Firefox 1.5 it fails with the error,
"x.contentWindow.document.body has no properties".

I've tried various changes, with no success.

How can I recode that statement, so it works in either browser?

TIA,
TC (MVP MSAccess)
http://tc2.atspace.com
 
T

TC

PS. The source of the IFRAME is an RSS XML file. The XML file specifies
an XLS stylesheet. The XSL stylesheet transforms the XML into HTML. At
present, the HTML (produced by that transformation) starts with <BODY>,
and ends with </BODY>.

TC
 
T

tudortihan

Hi folks

I've googled for an answer to this, with no success. Can someone please
jump in, and put me out of my misery! (I'm sure it's quite simple)

I have an invisible IFRAME, and a visible DIV:

<IFRAME id=myframe style="display:none" src="..."
onload="ShowNews(this)"></IFRAME>

<DIV id=mydiv></DIV>

I need to copy the content from the IFRAME, into the DIV. Everything
comes from the same domain, so there are definitely not any
cross-domain security issues.

This works fine in IE6:

function ShowNews(x) {
document.all.mydiv.innerHTML =
x.contentWindow.document.body.outerHTML
}

but in Firefox 1.5 it fails with the error,
"x.contentWindow.document.body has no properties".

I've tried various changes, with no success.

How can I recode that statement, so it works in either browser?

TIA,
TC (MVP MSAccess)
http://tc2.atspace.com

I don't know if this helps, but I've done something like this:

I've put a div tag inside the IFrame document and a small javascript
snippet at the end that takes the innerHTML from the div and sends it
to the parent window.

"index.html":
<html>
<head>
<script language="javascript" type="text/javascript">
<!--
var global_variable_1 = "<p>No page found</p>";
function make_global(variable_a)
{
global_variable_1 = variable_a;
}
function present_site()
{
document.getElementById("where_to_put_loaded_page").innerHTML =
global_variable_1;
}
//-->
</script>
</head>
<body onload="present_site()">
[...]
<div id="where_to_put_loaded_page">
Initial text here is: no page loaded.
</div>
<iframe style="visibility: hidden" src="page1.html"></iframe>
</body>
</html>

"page1.html" (loaded page):
<html>
<body>
[...]
<div id="meaningful_content">
Here I put the content that I want dynamically loaded in the main page.
</div>
[...]
<script language="javascript" type="text/javascript">
<!--

this.parent.make_global(document.getElementById("meaningful_content").innerHTML);

//-->
</script>
</body>
</html>

So basically I send the content from the IFrame to the main page via a
global variable and take/replace it via innerHTML. The only problem
with this is
that the iframe css doesn't get "shipped" to the main page. I've
temporarily solved that
by inlining the css, but if you find a better way, please tell me.
 
T

TC

Thanks for the suggestion. But in my case, the IFRAME content can't be
modified in the way you propose.

/Surely/ there's some way to get the content of an IFRAME, that will
work in Firefox?

This is the first time I've used Firefox, instead of IE. But at
present, IE works & Firefox doesn't. Grrrrrr #^%$%#$ :-(((

TC (MVP MSAccess)
http://tc2.atspace.com
 
S

Stephen Chalmers

Hi folks

I've googled for an answer to this, with no success. Can someone please
jump in, and put me out of my misery! (I'm sure it's quite simple)

I have an invisible IFRAME, and a visible DIV:

<IFRAME id=myframe style="display:none" src="..."
onload="ShowNews(this)"></IFRAME>

<DIV id=mydiv></DIV>

I need to copy the content from the IFRAME, into the DIV. Everything
comes from the same domain, so there are definitely not any
cross-domain security issues.

This works fine in IE6:

function ShowNews(x) {
document.all.mydiv.innerHTML =
x.contentWindow.document.body.outerHTML
}

but in Firefox 1.5 it fails with the error,
"x.contentWindow.document.body has no properties".

I've tried various changes, with no success.

You could try Googling: contentWindow +mozilla

To reference a div's content use:
document.getElementById('mydiv').innerHTML

You can reference the content of the document in an iframe via its
/name/, using:

window.frames[x].document.body.innerHTML

Mozilla doesn't appear to support outerHTML

It seems that contentWindow is available only as a property of the
value returned by document.getElementById, so to reference the iframe
by ID, try:

document.getElementById('mydiv').innerHTML =
document.getElementById(x).contentWindow.document.body.innerHTML;

or to amend your onload statement:

onload="ShowNews(this.id)"
 
C

Csaba Gabor

<IFRAME id=myframe style="display:none" src="..."
onload="ShowNews(this)"></IFRAME>

<DIV id=mydiv></DIV>

I need to copy the content from the IFRAME, into the DIV. Everything
comes from the same domain, so there are definitely not any
cross-domain security issues.

This works fine in IE6:

function ShowNews(x) {
document.all.mydiv.innerHTML =
x.contentWindow.document.body.outerHTML
}

Welcome to the wonderful world of two ways to do the same thing.
Now in your case, there are three differences!
FF does not have .all, .contentWindow, nor .outerHTML
but a div shouldn't be getting a <body> element, so perhaps try:

function ShowNews(x) {
document.getElementById('mydiv').innerHTML =
(x.contentDocument || x.contentWindow.document).body.innerHTML; }

where x is the IFRAME element (document.getElementById('myFrame');

Csaba Gabor from Vienna
 
T

TC

Geez, how hard could this friggin' be? !!

This is how I eventually managed to copy the content of an invisible
IFRAME, into a visible DIV, so it works in IE6 *and* FireFox 1.5.

Everything comes from the same domain, so there are no security issues.
This is the only solution that worked for me. All the others got
various errors in one or both browsers.


the DIV:

<DIV ID=mydiv>
</DIV>

the IFRAME:

<IFRAME ID=myframe SRC=... STYLE="display:none">
</IFRAME>

the code:

var x = document.getElementById('myframe');
document.getElementById('mydiv').innerHTML =
(x.contentDocument ||
x.contentWindow.document).documentElement.innerHTML;


Thanks to all who tried to help. I hope that this helps someone else!

TC (MVP MSAccess)
http://tc2.atspace.com
 
A

Askari

Cheers TC, that helped me!

I've googled around for this solution and read too many responses from
people 'guessing' that document.getElementById("myIframe").innerHTML
would work.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top