Search code examples
jqueryvariablesfancyboxparent

passing variable back to parent when fancybox window is closed


I was wondering if it is possible to pass back a variable from fancybox child to parent once child is closed?

function cleanUp(){
    var bla = $("#fancybox-frame").contents().find('input[name=pd_id]');
    alert(bla.val());
}
$("#tree .product a[class!=copy]").fancybox({
    'width'             : 770,
    'height'            : '95%',
    'autoScale'         : false,
    'transitionIn'      : 'none',
    'transitionOut'     : 'none',
    'type'              : 'iframe',
    'onCleanup'         : cleanUp
}); 

Solution

  • You can see in the fancybox api : onClosed... Will be called once FancyBox is closed

    $('.overlay').fancybox({
        onClosed: function() { 
            var bla = $('#targetFrame')[0].contentWindow.targetFunction(); 
        }
    });
    

    There is no child window/iframe, the box is simply an absolutely positioned div. It's in the same DOM as the page.