Jquery - fancybox and callback

sasa picture sasa · May 26, 2009 · Viewed 50.3k times · Source

I have problem with fancybox.
I want to write a function that will run when the fancybox opened. How and when to call the function?

Example:

function myFunc() {
    alert("Opened!");
}

$('.content a').fancybox({ 
    'hideOnContentClick': false ,
    'callBackOnShow': myFunc(), // This not working! It call function when page is loaded
    'frameWidth': 920,
    'frameHeight': 530
});

Answer

Matt Briggs picture Matt Briggs · May 26, 2009

Instead of myFunc() use myFunc. In javascript, a function with parens (and/or args) means you want to call it. A function name without them means you just want a reference to that function (which is probably what fancybox wants from you)