SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to access text box values in an iframe?

    Hi.

    Im trying to access a string in a textbox which Is located within an iframe on the parent document but the iframe is linked to a source html file.

    I know of
    document.getElementById('textbox').value
    But because its within an iframe which is getting its data from another html file Im having difficulty.

    Many thanks.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    The following one-liner reaches from a child window up to the parent, and in to an iframe to retrieve the content.

    Code javascript:
    window.opener.document.getElementsByTagName('iframe')[0].contentDocument.getElementById('content').innerHTML

    Resulting in:

    "<p>I am the iframe.</p>"

    Breaking it down:

    Code javascript:
    var parentDoc = window.opener.document;
    var iframeDoc = parentDoc.getElementsByTagName('iframe')[0].contentDocument;
    var iframeContent = iframeDoc.getElementById('content').innerHTML;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •