user1662658
user1662658

Reputation: 93

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());
}

Upvotes: 5

Views: 5650

Answers (1)

JFK
JFK

Reputation: 41143

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
}

Upvotes: 6

Related Questions