Colorbox iframe as modal : 如何向父级返回真/假



我发现很少找到使用colorbox作为模态框的文档。无论如何,我将iframe技术作为模态对话框,因此在我父母的页面中,JS是这样的:

    $(".confirmDeleteUser").colorbox({
        onOpen: function () {
            $("#colorbox").addClass("standardLightbox");
        },
        onLoad: function () {
            $('#cboxClose').remove();
        },
        iframe: true,
        href: "/modal_yesno.html",
        innerWidth: "530",
        innerHeight: "400", 
        fixed: true, 
        overlayClose: false
    });

父页面的HTML是这样的:

<a href="deleteuser.php?id=2" class="confirmDeleteUser">Delete user</a>

对于modal_yesno.html是这样的:

        $('.buttonNo').click(function () {
            return false;
            parent.$.fn.colorbox.close();
        });
        $('.buttonYes').click(function () {
            return true;
            parent.$.fn.colorbox.close();                
        });

但模态未关闭,返回值不会发送到父级。

所以问题是如何将真/假的 JavaScript 发送给父级并立即关闭 Colorbox?

返回值不会发送回父窗口,而是会发送回触发事件的元素;按钮。

我认为以下内容应该有效:

$('.buttonNo').click(function () {
   parent.$.fn.colorbox.close();
   window.parent.Confirmation(false);
});
$('.buttonYes').click(function () {
   parent.$.fn.colorbox.close();   
   window.parent.Confirmation(true);
});

其中 Confirmation() 是父页面中的一个方法。

最新更新