SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    *********! *********!!! jackli's Avatar
    Join Date
    Sep 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grabbing data from an iframe

    Is it possible to use javascript to grab data on a webpage -- with data that's only available on clientside?

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Javascript only has access to the iframe if the domain of the page where the javascript came from is the same as the domain of the iframe.

  3. #3
    *********! *********!!! jackli's Avatar
    Join Date
    Sep 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do you grab the content of the iframe using javascript? (can you point out the functions i should look up, outline the process?)

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    from the parent page...
    Code:
    <button onclick="alert(window.frames['myframe'].document.innerHTML);">test</button>
    where the iframe in question has name="myframe". You can also reference by index.

    that should get you started

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do you grab the content of the iframe using javascript?
    First, practice grabbing content on a page that does not have an iframe, e.g. document.getElementById("elmtID").innerHTML.

    After you feel comfortable with the way that works, you can get the content in an iframe the same way, but add:

    frames["iframeName"].

    onto the front of the commands. Just remember: if the page in the iframe is not your page, you won't be able to use javascript to get content from it.


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
  •