innerHTML of another frame

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christian Schmitt

    innerHTML of another frame

    I have a page as follows:

    <HTML>
    <FRAMESET ROWS="20%, 80%">
    <FRAME SRC="editor.htm l" NAME="editor">
    <FRAME SRC="testfile.h tml" NAME="reader">
    </FRAMESET>
    </HTML>

    editor.html contains the following code:

    code = document.docume ntElement.inner HTML

    which gives me the HTML-code of editor.html as expected.
    Now I want to read the HTML-code of testfile.html instead. But

    code = parent.reader.d ocument.documen tElement.innerH TML

    just returns

    <head></head><body></body>

    with Mozilla, and IE gives an error.
    Can somebody explain why this happens, and how I can solve it?
    Since the first case works on all browsers I tried, I was hoping to get
    a browser-independant method to read the sourcecode of another file.
    By the way, all files are local.

    Thanks

  • Lasse Reichstein Nielsen

    #2
    Re: innerHTML of another frame

    Christian Schmitt <cschmitt@cip.p hysik.uni-wuerzburg.de> writes:
    [color=blue]
    > I have a page as follows:
    >
    > <HTML>
    > <FRAMESET ROWS="20%, 80%">
    > <FRAME SRC="editor.htm l" NAME="editor">
    > <FRAME SRC="testfile.h tml" NAME="reader">
    > </FRAMESET>
    > </HTML>
    >
    > editor.html contains the following code:
    >
    > code = document.docume ntElement.inner HTML[/color]

    Where is it in editor.html? Inside a function or just directly inside
    a script tag. I.e., when is it executed?
    [color=blue]
    > which gives me the HTML-code of editor.html as expected.
    > Now I want to read the HTML-code of testfile.html instead. But
    >
    > code = parent.reader.d ocument.documen tElement.innerH TML[/color]

    I prefer to use the frames collection:
    var code = parent.frames['reader'].document...
    I have still to see a browser where it is required, though.
    [color=blue]
    > just returns
    >
    > <head></head><body></body>
    >
    > with Mozilla, and IE gives an error.[/color]
    [color=blue]
    > Can somebody explain why this happens, and how I can solve it?[/color]

    Most likely cause: The testfile.html page is not loaded yet at the
    time when you exexute the code.

    Solving it: Wait.
    Preferably until you are sure both pages have loaded. You can use the
    onload handler on the frameset to do that.

    Example:

    <frameset onload="window. LOADED = true;">

    and in editor.html:

    <script type="text/javascript">
    var code = null;
    function testCode() {
    if (parent.LOADED) {
    code = parent.frames['reader'].document.docum entElement.inne rHTML;
    } else {
    setTimeout(test Code,500);
    }
    }
    testCode();
    </script>

    Then don't use the code variable before it has been initialized.
    [color=blue]
    > Since the first case works on all browsers I tried, I was hoping to get
    > a browser-independant method to read the sourcecode of another file.[/color]

    You didn't try Netscape 4 or Opera 6, or any other browser not implementing
    the "innerHTML" property. It is not part of any standard, so depending on it
    might be dangerous. It is implemented in many modern browsers, though. Mostly
    for compatability with pages written for IE.
    [color=blue]
    > By the way, all files are local.[/color]

    As long as they are from the same domain, it should work.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...