SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    HTML inside an IFRAME

    Hey all,

    How can I access the HTML from a page in an IFRAME? I've tried this but it didn't work, when I clicked the button, 'undefined' came up in the DIV. Here's my function
    PHP Code:
    function loadPage file ) {
     
    document.getElementById('iframe').src file;
     
    document.getElementById('td').innerHTML document.getElementById('iframe').document.innerHTML;

    and here is the DIV and IFRAME
    Code:
    <div id='td' class='body'>
    <input id='file' type='text' /><br />
    <input id='button' type='button' value='Load' onClick="loadPage(document.getElementById('file').value)" />
    </div><br />
    <iframe id='iframe'></iframe>

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2002
    Location
    Newcastle, England
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Specify a name attribute in your iframe tag, such as

    Code:
    <iframe name="myiframe">
    Now to load a page within the iframe, which effectively is another window, use

    Code:
    var file = "page.html";
    myiframe.location.href = file;
    or to access elements use
    Code:
    myiframe.document.getElementById()
    Hope this point you in the write direction. I'm not entirely sure what you are trying to do with this javascript.
    WINDOWS XP
    IE 6
    1280x1024
    BROADBAND

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    As you could see from the code I posted, I am comfortable doing all that. I just need to access the HTML within the file that is active within the IFRAME.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •