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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Pickup

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

    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="Compositi on" ID="Composition ">
    </IFRAME>
    <SCRIPT LANGUAGE="JavaS cript1.2">
    <!--
    var scrollwindow = document.getEle mentById("Compo sition").conten tDocument;
    var page = "<P>hello</P>";
    scrollwindow.bo dy.innerHTML = page;
    //-->
    </SCRIPT>
    </BODY>
    </HTML>

    Thanks if advance for any help!
    Eric
  • DU

    #2
    Re: document.getEle mentById(&quot; ***&quot;).cont entDocument

    Eric Pickup wrote:
    [color=blue]
    > 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="Compositi on" ID="Composition ">
    > </IFRAME>[/color]

    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="nameCompo sition"
    id="idCompositi on">[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...A lt+P/Page style/Enable inline
    frames.]</iframe>
    [color=blue]
    > <SCRIPT LANGUAGE="JavaS cript1.2">[/color]

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

    <script type="text/javascript">
    [color=blue]
    > <!--
    > var scrollwindow = document.getEle mentById("Compo sition").conten tDocument;[/color]

    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["Compositio n"].document.body. innerHTML =
    "<P>hello</P>";

    would work, should work.
    [color=blue]
    > var page = "<P>hello</P>";
    > scrollwindow.bo dy.innerHTML = page;
    > //-->
    > </SCRIPT>
    > </BODY>
    > </HTML>
    >
    > Thanks if advance for any help!
    > Eric[/color]

    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.



    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:

    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


    Comment

    • DU

      #3
      Re: document.getEle mentById(&quot; ***&quot;).cont entDocument


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



      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.getEle mentById("idIfr ame").contentDo cument[...].



      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:

      - Resources, help and tips for Netscape 7.x users and Composer
      - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


      Comment

      Working...