simple iframe, calling with innerHTML - what am i doing wrong here?

Discussion in 'HTML' started by Ragnorack67, Mar 2, 2005.

  1. Ragnorack67

    Ragnorack67 Guest

    ....[something.htm]

    <div id=work>hello</div>


    ....[somethingelse.htm]

    <IFRAME id="thisframe" src="./something.htm"></IFRAME>

    <script>
    document.frames("thisframe").getElementById("work").innerHTML =
    "goodbye"
    </script>

    Thank you
     
    Ragnorack67, Mar 2, 2005
    #1
    1. Advertisements

  2. Ragnorack67

    Bert Guest

    change to:
    document.frames("thisframe").getElementById("work").body.innerHTML =

    grt Bert
     
    Bert, Mar 3, 2005
    #2
    1. Advertisements

  3. Ragnorack67

    Bert Guest

    sorry, makes nog sense...
     
    Bert, Mar 3, 2005
    #3
  4. Ragnorack67

    Bert Guest

    document.frames("thisframe").document.getElementById("work").innerHTML =
    "goodbye";

    that might be better...
     
    Bert, Mar 3, 2005
    #4
  5. Ragnorack67

    Ragnorack67 Guest

    Hmm, tried both and still can't get it to work. I'm yanking my hair out
    with this one. Nothing seems to work! Have you tested it out?
     
    Ragnorack67, Mar 3, 2005
    #5
  6. Ragnorack67

    Ragnorack67 Guest

    Hmm, tried both and still can't get it to work. I'm yanking my hair out

    with this one. Nothing seems to work! Any ideas?
     
    Ragnorack67, Mar 3, 2005
    #6
  7. Ragnorack67

    Bert Guest

    here's the source I tested it with:




    <html>

    <script>
    function test()
    {

    document.frames("thisframe").document.getElementById("work").innerHTML =
    "goodbye";

    }
    </script>

    <body onload = "test()">


    <IFRAME id="thisframe" src="./something.htm"></IFRAME>

    </body>
    </html>
     
    Bert, Mar 3, 2005
    #7
  8. Ragnorack67

    Ragnorack67 Guest

    Interesting. Why does it error out if you remove test(); from body
    onload? Anyway to make it a seperate call function, like <script>
    test(); </script> somewhere else?
     
    Ragnorack67, Mar 3, 2005
    #8
  9. Ragnorack67

    Ragnorack67 Guest

    Thank you -- works perfectly... Have a great weekend! :)))

    Sincerely --

    Alex
     
    Ragnorack67, Mar 3, 2005
    #9
  10. Ragnorack67

    DU Guest

    Followup-to: comp.lang.javascript only


    - frames collection are a property of the window object, not of the
    document.
    - you can access a single frame within the frames collection with
    frames["FrameName"] or with frames.FrameName but not with
    frames("IframeId"). You're confused in the correct way to access a frame.
    - when accessing a frame, the returned object is a window object, not a
    document.
    - contentDocument is a property of the iframe object which can return a
    reference to the document contained in the iframe. So assuming:

    <iframe id="idIframe" ...></iframe>

    then you can access such iframed document like this:

    document.getElementById("idIframe").contentDocument


    <head>
    ....
    <script type="text/javascript">
    function PopulateIframe()
    {
    var IframedDocumentBody = frames["thisframe"].document.body;
    var FirstParg = document.createElement("p");
    FirstParg.appendChild(document.createTextNode("goodbye"));
    IframedDocumentBody.appendChild(FirstParg);
    }
    </script>
    </head>

    <body onload="PopulateIframe();">
    ....

    Not tested but should work in Mozilla-based browsers.

    DU
    Followup-to: comp.lang.javascript only
     
    DU, Mar 4, 2005
    #10
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.