Tuesday, November 5, 2013

jQuery Fancybox: do a postback on parent page when closed

If you need the parent page to perform a postback when a child jQuery fancybox is closed, the following solution has worked for me.

Include the following function on the page (or refrenced via external file):
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
Then on the fancybox jQuery declaration, include the following:
$(".fancybox").fancybox({
'autoScale': false,
'width': 800,
'height': 800,
'type': 'iframe',
'scrolling': 'no',
'showCloseButton': true,
afterClose: function () {
__doPostBack();
}
});
 

No comments:

Post a Comment