最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Override colorbox onClose - Stack Overflow

programmeradmin0浏览0评论

I am using the following which works great. I am just wondering if it would be possible to override the onClosed after the box is loaded

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

I know that I can use the resize function after the box is loaded to resize the dimensions. Would it be possible to use the close functions similarly to acplish my goal?

I am using the following which works great. I am just wondering if it would be possible to override the onClosed after the box is loaded

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

I know that I can use the resize function after the box is loaded to resize the dimensions. Would it be possible to use the close functions similarly to acplish my goal?

Share Improve this question edited Mar 28, 2012 at 8:48 Eyad Fallatah asked Mar 28, 2012 at 8:39 Eyad FallatahEyad Fallatah 1,9484 gold badges24 silver badges36 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You can do it exactly the way you are attempting

$.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
    }
});

Or, you can pass a function name to the onClosed() too like

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

function overrideFunction() {
  /your overriding function
}

Although there might be cleaner solutions, what you could do is

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

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

and then overwrite the function afterwards rather than passing it as a closure to the properties of the colorbox.

Another work around was to override the close event to get a plete control of close event handling

    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;
        }
    };
发布评论

评论列表(0)

  1. 暂无评论