How to get return value from colorbox?

I have a colorbox that allows the user to select an image. How to get file name back from colorbox? (I noticed a function onClosed.)


Decision:

As @Gummy sugested, I used the onComplete function, as shown in the following example:

Return Page:

<input id="colorbox_hidden_return" type="hidden"/>

...

$("#whatever-you-want-to-click-on-to-get-the-color-box").click(function() {
        $.colorbox(
        {
            href: '<?= site_url('the-source-url') . '/' ?>' + id, 
            height: "600px;", 
            onClosed: function() { // called when the colorbox closes
                var image = $('#colorbox_return_hidden').val();

                // ... other processing - what ever the value was is in image
            }   
        });
    });

In color source

var image_name_var = "dynamicaly_change_this_name.png";

$('#submit-or-use-button-id').click(function() {
    $('#colorbox_return_hidden').val(image_name_var);
});
+5
source share
2 answers

Anytime the colorbox is open, you can call the element method to retrieve the jQuery object of the current element. From there, you can select an item and access the href property:

href = $.colorbox.element()[0].href;

, ( 'this') . , onComplete, , - :

$('#example').colorbox({onComplete:function(){
    href = this.href;
}});
+4

$(document).bind("cbox_complete", function(){
    var href = $.colorbox.element().attr("href");
    //do something else
});
0

All Articles