从页面加载到窗口中关闭kendo窗口

时间:2013-12-21 23:39:31

标签: javascript kendo-ui

我有一个以iframe打开并加载页面的kendo窗口。

如何从加载的页面中的按钮(或通过注册启动脚本)关闭该窗口?

具体来说,我有如下的kendo窗口:

var win = j$("<div />").kendoWindow({
        iframe: true,
        actions: ['Close'],
        draggable: true,
        modal: true,
        resizable: false,
        title: title,
        width: width,
        height: height,
        close: onClose,
        content: 'mypage.aspx',
        visible: false /*don't show it yet*/
    }).center().open();

如何从mypage.aspx关闭此窗口?

谢谢

1 个答案:

答案 0 :(得分:2)

这取决于 - 例如,如果您的页面中有按钮,并且事先知道id,则可以使用refresh事件(在内容加载完成时触发)附加一个关闭处理程序(fiddle):

var win = $("<div />").kendoWindow({
    iframe: true,
    actions: ['Close'],
    draggable: true,
    modal: true,
    resizable: false,
    title: title,
    width: width,
    height: height,
    close: onClose,
    content: 'mypage.aspx',
    refresh: function () {
        var that = this;            
        var iframe = $(this.element).find("iframe");

        // find the element, e.g. a button you want to close with
        var button = $(iframe).contents().find("#my-button");
        $(button).click(function() {
            that.close();
        });
    },
    visible: true 
}).data().kendoWindow.center().open();

作为替代方案,您可以从iframe中访问window.parent以访问Kendo窗口,或访问您在父窗口中定义的关闭功能。 请注意,这仅在内容从同一域,子域和端口(同源策略)提供时才有效。

相关问题