SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing value of input in parent document

    I have the following structure:

    Code:
    <html><body>
    ...stuff ..
    <input id="test-input" type="text" />
    <iframe id="test-frame" src="whatever.php" />
    .. more stuff ..
    </body></html>
    I need to change value of "test-input" from within that iframe. Typically I'd use
    Code:
    parent.document.getElementById('test-input').value = 'whatever';
    but the problem is, iframe and document are on different domains, so I can't access parent.document

    Is there some workaround for it? I have full access to both top and iframe document, so can add any javascript to both.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by CyberAlien View Post
    Is there some workaround for it? I have full access to both top and iframe document, so can add any javascript to both.
    Can the child execute a parent function, that changes it instead?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tested it, parent function can't be executed. Getting error "permission denied to access property 'testFunction'"

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    You may require a cross-domain communication solution then, one of which is easyXDM
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!


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
  •