gpt4 book ai didi

javascript - 从加载到窗口的页面关闭剑道窗口

转载 作者:行者123 更新时间:2023-11-30 17:42:46 25 4
gpt4 key购买 nike

我有一个剑道窗口,它作为 iframe 打开并加载一个页面。

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

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

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 关闭此窗口?

谢谢

最佳答案

这取决于 - 例如,如果您的页面中有按钮,并且您事先知道 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();

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

关于javascript - 从加载到窗口的页面关闭剑道窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20724681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com