把以下代码复制到你的公用js库中:
var ModalDialogWindow = function() {
this.constructor();
this.window = Ext.extend(Ext.Window,{
closeable:true,
closeAction:'close',
draggable:true,
plain:true,
modal:true
});
}
ModalDialogWindow.prototype.initialize = function(obj) {
if(!IsArray(obj)) {
if (typeof(obj) == 'string') {
obj = obj.split(';');
for(var i = 0; i < obj.length; i++) {
obj = obj.split(':');
switch(obj[0]) {
case 'dialogHeight': this.dialogHeight = parseInt(obj[1]);break;
case 'dialogWidth': this.dialogWidth = parseInt(obj[1]);break;
case 'dialogLeft': this.dialogLeft = parseInt(obj[1]);break;
case 'dialogTop': this.dialogTop = parseInt(obj[1]);break;
case 'resizable': this.resizable = obj[1];break;
case 'scroll': this.scroll = obj[1];break;
case 'title': this.title = obj[1];break;
}
}
} else if(typeof(obj) == 'object') {
for(var index in obj) {
switch(index) {
case 'dialogHeight': this.dialogHeight = parseInt(obj[index]);break;
case 'dialogWidth': this.dialogWidth = parseInt(obj[index]);break;
case 'dialogLeft': this.dialogLeft = parseInt(obj[index]);break;
case 'dialogTop': this.dialogTop = parseInt(obj[index]);break;
case 'resizable': this.resizable = obj[index];break;
case 'scroll': this.scroll = obj[index];break;
case 'title': this.title = obj[index];break;
}
}
}
}
};
ModalDialogWindow.prototype.constructor = function() {
this.obj = this;
this.returnValue = null;
this.win = {};
// showModalDialog arguments
this.sURL = '';
this.dialogArguments = null;
//sFeatures arguments
this.dialogHeight = 100;
this.dialogWidth = 100;
this.dialogLeft = 0;
this.dialogTop = 0;
this.resizable = false;
this.scroll = true;
this.title = '';
this.html = '';
};
ModalDialogWindow.prototype.destroy = function() {
this.constructor.call(this);
}
ModalDialogWindow.prototype.showModalDialog = function(sURL,vArguments,sFeatures) {
if(this.sURL != '') {this.destroy()}
this.sURL = sURL;
if(arguments.length < 3) {sFeatures = vArguments;vArguments = null;}
this.dialogArguments = vArguments?vArguments:null;
this.initialize(sFeatures);
window.win = this.obj;
this.html = '<iframe id="mdFrame" name="mdFrame" width="' + this.dialogWidth + '" height="' + this.dialogHeight + '" frameborder="0" src="' + this.sURL + '"></iframe>';
this.win = new this.window({
id: 'mdWin',
title: this.title,
resizable: this.resizable,
autoHeight: this.scroll,
width: this.dialogWidth,
height: this.dialogHeight,
html: this.html
});
if(this.dialogLeft && this.dialogTop) {this.win.setPosition(this.dialogLeft,this.dialogTop);}
this.win.addListener({
'show':function() {},
'close':function() {window.win = null;}
});
this.win.show();
};
--------------------------------------------------------------------------------------------
父页面调用代码:
<input name="test" type="text" />
function getValue(obj) {
var _win = new ModalDialogWindow();
_win.showModalDialog('sub.html','','title:test;dialogWidth:600;dialogHeight:400');
_win.win.on('beforeclose',function(){
obj.value = _win.returnValue;
});
}
--------------------------------------------------------------------------------------------
子页面传值变量:
<script>parent.win.returnValue = '要传的变量'</script>
--------------------------------------------------------------------------------------------
有什么可改进的地方还请大家指点