document.getElementById("***").contentDocument

E

Eric Pickup

I'm having a problem with the following html (I've simplified it down
to a simple test case). Could anyone point out why Mozilla is having
problems with this (I've tried so many variations that I can't think
of any more). In the actual code I have an if statement to handle IE
but I need the code to work in Mozilla and IE.

<HTML>
<BODY>
<IFRAME width="100" height="100" NAME="Composition" ID="Composition">
</IFRAME>
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
var scrollwindow = document.getElementById("Composition").contentDocument;
var page = "<P>hello</P>";
scrollwindow.body.innerHTML = page;
//-->
</SCRIPT>
</BODY>
</HTML>

Thanks if advance for any help!
Eric
 
D

DU

Eric said:
I'm having a problem with the following html (I've simplified it down
to a simple test case). Could anyone point out why Mozilla is having
problems with this (I've tried so many variations that I can't think
of any more). In the actual code I have an if statement to handle IE
but I need the code to work in Mozilla and IE.

<HTML>
<BODY>
<IFRAME width="100" height="100" NAME="Composition" ID="Composition">
</IFRAME>

1- There is no src attribute and src attribute value for your iframe here.

2- I strongly suggest you always give different and distinct attribute
values to id and name for several reasons: it helps code readability,
code debugging with debuggers, code review by others. I personally use
prefixing in this manner:

<iframe width="100" height="100" name="nameComposition"
id="idComposition">[Your user agent does not seem to support iframes or
is currently configured not to display iframes. If you're using Opera
6+, you can with File/Preferences...Alt+P/Page style/Enable inline
frames.] said:
<SCRIPT LANGUAGE="JavaScript1.2">

language is a deprecated attribute; type has superseded language and is
both backward and forward compatible. So,

<!--
var scrollwindow = document.getElementById("Composition").contentDocument;

This is wrong. Your iframe Composition is an element of a page here.
To modify dynamically the content of your iframed document,
I'm almost 100% sure that

var scrollwindow = frames["Composition"].document.body.innerHTML =
"<P>hello</P>";

would work, should work.
var page = "<P>hello</P>";
scrollwindow.body.innerHTML = page;
//-->
</SCRIPT>
</BODY>
</HTML>

Thanks if advance for any help!
Eric

There is a much better way to do what you are attempting to do here.
Many months ago, I wrote a script just achieving what you want to do,
and it works extremely well for MSIE 6 for Windows, Mozilla-based
browsers (17 different browsers), Opera 7 and most likely other W3C web
standards compliant browsers. The code uses only valid W3C markup code,
valid css code and W3C DOM 2 properties and methods.

http://www10.brinkster.com/doctorunclear/HTMLJavascriptCSS/MainPage.html

Opera 7 has a bug with disabling button while MSIE 6 for Windows has a
padding issue with iframes.
Don't bookmark the page as I'll probably tune and tweak again the page
and rename the page.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
 
D

DU

Ok. I remove the previous MainPage.html from my site.

http://www10.brinkster.com/doctorunclear/HTMLJavascriptCSS/MainPageStaticIframe.html

is basically what you were trying to do. Because MSIE 6 does not support
contentDocument, it's preferable to avoid it and resort to another way
to reference the document: i.e.
frames["nameIframe"].document.[...]
which is more widely supported than
document.getElementById("idIframe").contentDocument[...].

http://www10.brinkster.com/doctorunclear/HTMLJavascriptCSS/MainPageDynamicIframe.html

is another variant where you try to dynamically modify a document
(inserting Hello) which is loaded inside a dynamically created iframe.
You'll see that Opera 7.x and Mozilla-based browsers are much more
powerful than MSIE 6 for windows in this sort of scripts.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top