Fancybox iframe return value on close

I use fancxbox, I can pass the variable back from fancybox to the parent.

The child page has a text box named banner_width1( <input name="banner_width" id="banner_width1" type="text" size="5" value="1000"/>)

'onClosed':function() 
{
alert($("#banner_width1").val());
var x = $("#fancybox-frame").contentWindow.targetFunction();
alert(x.val());
}
+5
source share
1 answer

If you use fancybox v1.3.4, you will not be able to get the value ( .val()) using the callback onClosed, because it onClosedwill be executed when all the fancybox content has already been deleted. You rather use onCleanupinstead (you can still notify the value xafter closing fancybox)

so for Fancybox v1.3.4 use these API options

"onCleanup": function(){
 x = $('#fancybox-frame').contents().find('#banner_width1').val();
},
"onClosed": function(){
 alert("the value of input#banner_width1 is : "+x); // optional
}

, var x; script, .

Fancybox v2.x API

beforeShow : function(){
 x = $('.fancybox-iframe').contents().find('#banner_width1').val();
},
afterClose: function(){
 alert("the value of input#banner_width1 is : "+x); // optional
}
+6

All Articles