最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Override colorbox onClose - Stack Overflow

matteradmin3PV0评论

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;
        }
    };
Post a comment

comment list (0)

  1. No comments so far