SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    0 Post(s)
    0 Thread(s)

    jQuery DOM in iframe

    Inside an iframe I need to execute a script which will get a value from the div that wraps around the iframe.

    <div style="border-color:red">
    <iframe src="" class="the-iframe">
    //script executed in the iframe

    Both scripts are on the same domain, although may be different protocols (http/https sometimes).

    Also, the iFrame where the script is used will always be the last one in the DOM (if more than one exist).

    Neither of these work:

    $('iframe', window.parent.document).last.before.css('border-color');

    Is it possible, and if so what do I do?

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    0 Post(s)
    0 Thread(s)
    Hi John,

    The protocol, domain and even port of the page containing the iframe need to match the iframe's protocol, domain and port.
    You won't get it to work otherwise.

    To access the border-color of the DIV-element (which is the parent of the iframe, not a sibling) in the parent page from within the iframe, you could use:
    Code JavaScript:
    $(".the-iframe", parent.document.body).parent().css('border-color');

    Hope it helps ;-)
    FOR SALE: 1 set of morals, never used, will sell cheap


Posting Permissions

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