Shaun Mccran

My digital playground

13
A
P
R
2011

Triggering functions when closing a fancybox pop up

The FancyBox JQuery plugin is a popular lightbox style plugin that allows you a variety of options to 'pop' different types of content up into a users view.

I needed to have the parent page change when the user had performed an action within the pop up. But how to do this?

FancyBox (http://fancybox.net/) has a 'onClosed' option to allow you to embed a function call whenever the user closes the lightbox.

The format of this is a little tricky, so here is an example:

view plain print about
1// pop up handler
2$.fancybox({
3    'autoDimensions':    false,
4    'speedIn'            : 600,
5    'speedOut'            : 200,
6    'overlayShow'        : true,
7    'width'            : 440,
8    'height'            : 340,
9    'type'            : 'iframe',
10    'scrolling'            : 'no',
11    'transitionIn'        : 'elastic',
12    'transitionOut'        : 'fade',
13    'enableEscapeButton'    : 'true',
14    'overlayOpacity'        : 0.5,
15    'title'            : '',
16    'href'             : 'yourpage.htm',
17    'onClosed'            : function() { alert('closed'); }

You can build any function you want in this call, it is normal JavaScript after all, if you just wanted to reload the page you could have a refresh function:

view plain print about
1function() {
2
3parent.location.reload(true);
4
5}

This seems to work for any method of closing the Fancybox as well, so it will always fire.

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Back to top