Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fancybox iframe type return value on close

I'm using fancxbox,it is possible to pass back a variable from fancybox child to parent.

In the child page there is text field called 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());
}
like image 633
user1662658 Avatar asked Sep 13 '12 12:09

user1662658


1 Answers

If you are using fancybox v1.3.4 then you won't be able to get the value (.val()) using the onClosed callback because onClosed will be executed when all the fancybox content has been already removed. You rather use onCleanup instead (you can still alert the value of x after closing fancybox though)

so for Fancybox v1.3.4 use this API options

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

make sure that you have declared var x; on top of your script to make it accessible from any callback or any other function.

for Fancybox v2.x use this API options

beforeShow : function(){
 x = $('.fancybox-iframe').contents().find('#banner_width1').val();
},
afterClose: function(){
 alert("the value of input#banner_width1 is : "+x); // optional
}
like image 124
JFK Avatar answered Oct 04 '22 05:10

JFK