Ref:http://stackoverflow.com/questions/12406232/fancybox-iframe-type-return-value-on-close
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
}
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
}
ผมนำไปประยุกต์ใช้ดังนี้
<script type="text/javascript">
$(document).ready(function() {
$('#rptDate').datepicker({ dateFormat:'yy-mm-dd'}); //--อันนี้ปฎิทินใช้ jquery ui ครับ
$(".openboxV2").fancybox({ //--อันนี้ใช้งาน fancybox ทั่วไป
'padding' : 30,
'hideOnContentClick': false
});
/*---อันนี้ต้องการ return กลับเพื่อไปเปลี่ยนข้อมูล ที่แสดงตอนโหลดครั้งแรก ตามที่อัปเดทในฐานข้อมูล ทำให้เราไม่ต้องโหลดใหม่เมื่อมีการอัปเดทข้อมูลในแถว ----*/
$(".addWkCommentNotReload").fancybox({
'width' : 300,
'height' : 80,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe',
onCleanup: function(){
id = $('#fancybox-frame').contents().find('#wk_id').val();
str = $('#fancybox-frame').contents().find('#wk_comment').val();
},
onClosed: function() {
//alert('id:'+id+' str:'+str);
write_txt(id,str);
alert("Closed!");
}
});
});
function write_txt(id,str){
//alert("id :"+id+" str"+str);
$('#'+id).text(str);
}
</script>