您的位置:首页 > Web前端 > JavaScript

Extjs 如何在关闭窗口时提示是否关闭

2012-10-31 11:53 543 查看
          

Extjs关闭窗口前有一个事件是beforeclose,当返回false时,extjs不再执行关闭操作。

由于使用Ext的show方法是异步执行,因此在异步弹出选择框时,仍然执行了关闭操作。

所以第一步是给窗口对象在   Ext.MessageBox.show 后添加return false;

   openerWin.on("beforeclose", function() {    

           Ext.MessageBox.show({});

           
return false; }); 

第二步,在关闭对话框的yes按钮里添加事件 openerWin.close(); 此时会再次调用窗口关闭操作。

第三步,加入控制变量,判断是否触发了关闭操作。

 

代码示例:

             openerWin = Ext.ux.Util.createWindow({

                        id : id,

                        title : appletName,

                        width : this.width + 10,

                        height : this.height + 35,

                        plain : true,

                        closable : true,

                        resizable : true,

                        html : htmlContent

                    });

            var ifclose=false;

            openerWin.on("beforeclose", function() {

            if(ifclose){ return true;}

            Ext.MessageBox.show({

            title : i18n.prompt,

            msg : i18n.ldap_prompt_operation_option,

            buttons : Ext.Msg.YESNO,

            icon : Ext.Msg.WARNIN,

            fn : function(btn) {

                if (btn == 'yes') {

                    ifclose=true;

                    openerWin.close();

                    }

            }

         });

        return false;

            });
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: