我想在Window关闭时(点击右上角的"X"),弹出提示框,由用户确认是否关闭窗口,这样该如何实现?

解决方案 »

  1.   

            window.onbeforeunload = function() {
                try {
                    return "是否关闭?";
                } catch (e) { }
            }
      

  2.   

    window事件属性
      

  3.   

    例如你的window的实例是win那么 beforeclose 事件就可以了win.on('beforeclose',function(){
        return confirm('是否关闭');
    });赶紧结贴吧
      

  4.   

    这样好像不行吧,Ext的Api的window事件中没有onbeforeunload 这个事件呀!
      

  5.   

    回复于:2011-06-30 15:13:20例如你的window的实例是win那么 beforeclose 事件就可以了win.on('beforeclose',function(){
      return confirm('是否关闭');
    });赶紧结贴吧 
    这个也是了,就是不行的?是否还有什么属性要设置吗?
      

  6.   


     Ext.onReady(function () {
                 Ext.create('Ext.window.Window', {
                     title: 'Hello',
                     height: 200,
                     width: 400,
                     listeners: {
                         beforeClose: function (_this) {
                             return confirm("确认删除吗?");
                         }
                     }             }).show();
             });
      

  7.   

    var codeWindow = new Ext.Window(
    {
    layout : 'fit',
    width : 300,
    height : 200,
    resizable : false,
    draggable : true,
    closeAction : 'hide',
    title : '<span style="font-weight:normal">新增层面</span>',
    // iconCls : 'page_addIcon',
    modal : true,
    collapsible : false,
    closable:true,
    listeners:{
       beforeClose:function(){
          return confirm("确认关闭吗?");
       }
    },
    titleCollapse : true,
    maximizable : false,
    buttonAlign : 'right',
    border : false,
    animCollapse : true,
    animateTarget : Ext.getBody(),
    constrain : true,
    items : [ formPanel ],
    buttons : [
    {
    text : '保存',
    iconCls : 'acceptIcon',
    handler : function() {
    if (codeWindow.getComponent('dataSourceForm').form.isValid()) {
        Ext.Msg.confirm('提示','确认要新增层面吗?',function(btn,text){
           if(btn=='yes'){
              codeWindow.getComponent('dataSourceForm').form.submit( {
    url : './sjjType.ered?reqCode=saveDivlay',
    waitTitle : '提示',
    method : 'POST',
    waitMsg : '正在处理数据,请稍候...',
    success : function(form,action) {
    store.reload();
        var msg = action.result.msg;
    Ext.MessageBox.alert('提示',msg);
    codeWindow.hide();
    },
    failure : function(form,action) {
    var msg = action.result.msg;
    Ext.MessageBox.alert('提示',msg);
    codeWindow.getComponent('dataSourceForm').form.reset();
    }
    });
           }
        });

    } else {
    // 表单验证失败
    }
    }
    }, {
    text : '重置',
    id : 'btnReset',
    iconCls : 'tbar_synchronizeIcon',
    handler : function() {
    clearForm(formPanel.getForm());
    }
    },{
    text : '关闭',
    iconCls : 'deleteIcon',
    handler : function() {
        Ext.Msg.confirm('确认','确认退出该窗口吗?',function (btn,text){
         if(btn=='yes')
         {
           codeWindow.hide();
         }
         });

          }
           }  ]
    });
    codeWindow.on('beforeClose',function(){
      return confirm("确认关闭?");
    });
    我这两种方式用了,貌似还是不行?
      

  8.   

    找到原因了,closeAction : 'hide',这个属性是hide,应该用beforehide事件,或是把closeAction:'close';