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
});
In the parent, I define
var $_returnvalue = false;
And onClosed looks like this:
onClosed: function() {
if ($_returnvalue != false)
{
// Do something in the parent
}
And in the fancybox page, when something is ready to be returned, I set that value to parent.$_returnvalue and then close the box. This works well for selecting something from a list and passing that value back to the calling page.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With