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

javascript - Callback from the parent when colorbox is closed from iframe - Stack Overflow

programmeradmin4浏览0评论

I understand you can do a callback with colorbox when you use the close button per :

onClosed:function(){ alert('onClosed: colorbox has pletely closed'); }

however I am closing colorbox from the iframe itself after a successful ajax request like :

if(json.status == 'success') {
parent.$j.fn.colorbox.close();
}

My question is how can I then have the parent window be notified that the colorbox has been closed and then run a callback from there? Is this possible?

I understand you can do a callback with colorbox when you use the close button per :

onClosed:function(){ alert('onClosed: colorbox has pletely closed'); }

however I am closing colorbox from the iframe itself after a successful ajax request like :

if(json.status == 'success') {
parent.$j.fn.colorbox.close();
}

My question is how can I then have the parent window be notified that the colorbox has been closed and then run a callback from there? Is this possible?

Share Improve this question edited Dec 13, 2011 at 19:12 Zac asked Dec 13, 2011 at 18:44 ZacZac 12.9k21 gold badges77 silver badges124 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

The onClosed event will be fired even when the colorbox is closed from within your iframe, and it will be fired in the context of the parent already. So you could just put your callback in the onClosed function:

$("a.pic").colorbox({
    onClosed: function() {
        myCallback;
        //do other stuff
    },
    //or if everything is in the callback:
    onClosed: myCallback,
    href:"myDog.jpg"
});

As far as notifications, if everything is in your callback, that's all you need. If you've got more going on and can't get everything into that callback, you could use jQuery's trigger to fire another "closed" event:

$.colorbox({
    onClosed: function() {
        $(window).trigger("colorboxClosed");
    },
    href:"myDog.jpg"
});

Then bind functions to that custom event:

$(window).bind("colorboxClosed", function() {
    alert("closed");
});

If you are using jQuery 1.7+ and don't need backwards patibility, it's remended that you use the on function instead of bind.

发布评论

评论列表(0)

  1. 暂无评论