1

我是 ExtJS 的新手。

这是我的窗口定义:

this.dialog = new Ext.Window({
title : "About us",
layout  : 'anchor',
modal   : true,
autoEl : {
        tag : "iframe",
        id: "myframe",
        src : "../editor/actorseditor.html",
        height: 500,
        width : 600
} });   
this.dialog.show();

我想从“actorseditor.html”关闭我的对话窗口。

如何实现这一点。打开的窗口也没有关闭按钮。

提前致谢

4

3 回答 3

1

仅当 iFrame 中的 html 页面来自与父页面相同的应用程序时,这才有效。或者至少协议、子域、域和端口都是相同的。

您需要在父页面中公开一个全局函数,该函数将由在子页面 (iframe) 中运行的 JavaScript 调用。

在您的子页面中,您调用:

 if (window.parent && window.parent.myGlobalFunction) {
       window.parent.myGlobalFunction('hello!');
  }

在您的父页面中,您包含以下全局函数(当然可以根据需要命名):

function myGlobalFunction(input){
        console.log('message received:'+input);
        MyApp.app.fireEvent('closeMyWindow',input);
    }

这假设您正在使用 MVC,并且您创建了属性“app”并在应用程序启动功能中将其设置为“this”。并且您有一个控制器正在侦听这样的应用程序范围的事件:

Ext.define('MyApp.controller.Qnum', {
    extend:'Ext.app.Controller',
    init:function(){
        this.control({
            ...
        });
        //listen for app wide event fired by : MyApp.app.fireEvent('closeMyWindow',input);
        this.application.on({
            closeMyWindow: this.closeWindowItsDrafty,
            scope: this
        });
    },
    closeWindowItsDrafty:function(){
       //get reference to my window
       //call myWindow.close();
    }
于 2013-01-29T01:03:31.490 回答
0

我假设在 actoreditor.html 中,你必须有一个按钮

在此按钮中,您可以设置此侦听器:

listeners : {
    click : function () {
         Ext.getCmp('yourdialogid').close();
    }
}

您还需要在对话框中添加一个 id。

于 2013-01-28T16:16:57.730 回答
0

请在您的关闭按钮侦听器中尝试以下操作:

var parentDialogWindow = window.parent.Ext.cmp('ID_OF_DIALOG_WINDOW');
parentDialogWindow[parentDialogWindow.closeAction]();
于 2017-08-25T22:19:22.030 回答