gpt4 book ai didi

javascript - 从 iframe 关闭颜色框时从父级回调

转载 作者:行者123 更新时间:2023-11-29 17:26:20 32 4
gpt4 key购买 nike

我知道您可以在使用关闭按钮时使用 colorbox 进行回调:

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

然而,在成功的 ajax 请求之后,我正在从 iframe 本身关闭 colorbox,例如:

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

我的问题是如何通知父窗口颜色框已关闭,然后从那里运行回调?这可能吗?

最佳答案

即使在您的 iframe 中关闭颜色框时,onClosed 事件也会被触发,并且它已经在父级的上下文中被触发。所以你可以把你的回调放在 onClosed 函数中:

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

就通知而言,如果所有内容都在您的回调中,这就是您所需要的。如果你有更多的事情要做并且不能把所有的东西都放到那个回调中,你可以使用 jQuery 的触发器来触发另一个“关闭”事件:

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

然后将函数绑定(bind)到该自定义事件:

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

如果您使用的是 jQuery 1.7+ 并且不需要向后兼容,建议您使用 on 函数而不是 bind

关于javascript - 从 iframe 关闭颜色框时从父级回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8494452/

32 4 0
文章推荐: android - 如何使用 Jsoup 从
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com