Javascript 覆盖颜色框onClose

Javascript 覆盖颜色框onClose,javascript,jquery,colorbox,Javascript,Jquery,Colorbox,我使用下面的方法,效果很好。我只是想知道是否有可能在盒子加载后覆盖onClosed $.colorbox({href:"fff.html", onClosed:function(){ window.parent.location.reload(true); } }); 我知道我可以在加载框后使用调整大小功能来调整尺寸。是否可以使用类似的关闭函数来实现我的目标?虽然可能有更干净的解决方案,但您可以做的是 // in the window scope! Can be exp

我使用下面的方法,效果很好。我只是想知道是否有可能在盒子加载后覆盖onClosed

    $.colorbox({href:"fff.html",
    onClosed:function(){ window.parent.location.reload(true); }
    });

我知道我可以在加载框后使用调整大小功能来调整尺寸。是否可以使用类似的关闭函数来实现我的目标?

虽然可能有更干净的解决方案,但您可以做的是

// in the window scope! Can be explicitely set with
// window.onColorboxClose without var before it.
var onColorboxClose = function(){
};

$.colorbox({
  href:"fff.html",
  onClosed:onColorboxClose 
});

然后重写函数,而不是将其作为colorbox属性的闭包传递。

虽然可能有更干净的解决方案,但您可以做的是

// in the window scope! Can be explicitely set with
// window.onColorboxClose without var before it.
var onColorboxClose = function(){
};

$.colorbox({
  href:"fff.html",
  onClosed:onColorboxClose 
});

然后再覆盖函数,而不是将其作为colorbox属性的闭包传递。

您可以完全按照尝试的方式来完成

$.colorbox({href:"fff.html",
    onClosed:function(){ 
       //This is your method that triggers onClose
       // SO go ahead, override it 

       //You can also call multiple function on it like

       function1(); //call function 1
       function2(); //call function 2
    }
});
或者,您也可以向onClosed()传递函数名,如下所示


你可以完全按照你正在尝试的方式来做

$.colorbox({href:"fff.html",
    onClosed:function(){ 
       //This is your method that triggers onClose
       // SO go ahead, override it 

       //You can also call multiple function on it like

       function1(); //call function 1
       function2(); //call function 2
    }
});
或者,您也可以向onClosed()传递函数名,如下所示


另一个解决方法是重写关闭事件,以获得对关闭事件处理的完全控制

    var c_close = $.fn.colorbox.close;
    // Now disable the close function
    $.fn.colorbox.close = function(){

        if(confirm('Are you sure?')){
            c_close();
        } else {
            return false;
        }
    };

另一个解决方法是重写关闭事件,以获得对关闭事件处理的完全控制

    var c_close = $.fn.colorbox.close;
    // Now disable the close function
    $.fn.colorbox.close = function(){

        if(confirm('Are you sure?')){
            c_close();
        } else {
            return false;
        }
    };