Search code examples
jqueryiframeparent

targeting element in parent window from iframe with jquery


I'm trying to close an iframe which opens in a pop up style. The button to close it is within the iframe. This is what I have inside the iframe:

$("#closeOverlayButton").click(function() {
    $('#closeOverlayButton', parent.document).closeOverlay();
});

The button has id of closeOverlayButton, and the function I'm calling is called closeOverlay (which works when it's not called from an iframe).

Any idea what I'm doing wrong? Thanks


Solution

  • You can use something like this:

    $('#closeOverlayButton', window.parent.document).closeOverlay();
    

    The ifram URI and parent URI should be in same domain.