Search code examples
fancyboxfancybox-2

trigger fancybox iframe without click but when a condition is met


Simple question, I dont think its possible but hopefully someone can proof me wrong.

Is it possible to trigger fancybox without a click but rather if an event is met

Example

if(balance<1){
#fancyBoxOpen
}
else{
Continue to page
}

Solution

  • Yes, it's possible.

    You could create a function that triggers fancybox like :

    var triggerFancybox = function () {
        var content = "Sorry, the balance is less than 1";
        jQuery.fancybox.open(content);
    }
    

    And call that function when your condition is met like :

    if (balance < 1) {
        triggerFancybox();
    }
    

    See JSFIDDLE

    .... or another with a hard-coded condtion