iframe

Discussion in 'Javascript' started by Jeff Thies, Jul 4, 2003.

  1. Jeff Thies

    Jeff Thies Guest

    I have an iframe (IE5):

    <iframe name="frame1" id="frame1" src="some_source">test</iframe>

    that test appears outside the iframe, the src contents are in the iframe
    though

    I'd like to read the iframe.

    var frame1=document.getElementById('frame1').innerHTML;

    What I get is "test", not what the contents of the iframe actually is.

    What have I done wrong?

    Jeff
     
    Jeff Thies, Jul 4, 2003
    #1
    1. Advertising

  2. Jeff Thies <> writes:

    > I have an iframe (IE5):
    >
    > <iframe name="frame1" id="frame1" src="some_source">test</iframe>
    >
    > that test appears outside the iframe, the src contents are in the iframe
    > though
    >
    > I'd like to read the iframe.
    >
    > var frame1=document.getElementById('frame1').innerHTML;
    >
    > What I get is "test", not what the contents of the iframe actually is.
    >
    > What have I done wrong?


    You want to access the content page in the frame. That is a completely
    different page, so its HTML is not part of the iframe element on this
    page.

    What you can do is either:

    var frame1=document.getElementById('frame1');
    var iframeDocument = frame1.contentWindow ? frame1.contentWindow.document
    : frame1.contentDocument;
    var root = iframeDocument.documentElement || iframeDocument.body;
    var HTML = root.innerHTML;

    or

    var frame1Document = frames['frame1'].document;
    var root = iframeDocument.documentElement || iframeDocument.body;
    var HTML = root.innerHTML;

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Jul 4, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    729
  2. mi
    Replies:
    4
    Views:
    14,314
    dorayme
    May 21, 2008
  3. elca
    Replies:
    0
    Views:
    600
  4. Scott
    Replies:
    6
    Views:
    1,025
    [MSFT]
    Apr 14, 2004
  5. Daedalous
    Replies:
    3
    Views:
    828
    Daedalous
    Jan 16, 2004
Loading...

Share This Page