Reputation: 4896
I have a kendo window which is open as iframe and loads a page.
How can I close that window from a button (or by registering a startup script) from the loaded page?
Specifically I have the kendo window as below:
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();
How can I close this window from mypage.aspx?
Thank you
Upvotes: 1
Views: 3137
Reputation: 18402
It depends - if, for example, you have buttons inside your page, and you know the id
beforehand, you can use the refresh
event (which is triggered when the content has finished loading) to attach a close handler (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();
As an alternative, you could access window.parent from within your iframe
to get access to the Kendo Window, or to a close function you have defined in the parent window.
Note that this will only work if the content is served from the same domain, subdomain and port (same-origin policy).
Upvotes: 2