希望在明天

如果,你没有耐心等待成功的到来,那么,你将用一生的耐心去面对失败。

使模式对话框显示在IE窗口的中间



默认情况下,调用showModalDialog显示的模式对话框是在屏幕的中间,通过下面的代码可以使对话框显示在IE窗口的中央,无论IE窗口的大小和位置。

var wWidth=800;
var wHeight=600;
var wLeft = 0;
var wTop  = 0;

function GetDialogParams(width, height)
{
    
var mLeft = 0;
    
var mTop  = 0;
    
var wndDet = new GetWindowDetails();
    mLeft 
= parseInt(((wndDet.wWidth - width)/2)+wndDet.wLeft)
    mTop 
=  parseInt(((wndDet.wHeight - height)/2)+wndDet.wTop)
    
return 'dialogHeight: '+height+'px; dialogWidth: '+width+'px; dialogTop: '+mTop+'px; dialogLeft: '+mLeft+'px; edge: Raised; center: No; resizable: no; status: no; location:no; scroll: no; help: no;'
}


function GetWindowDetails () {
    WindowSize();
    GetWindowLocation();
    
this.wWidth = wWidth;
    
this.wHeight = wHeight;
    
this.wLeft = wLeft;
    
this.wTop  = wTop;

    
return this;
}


// Get Window Size 
function WindowSize()
{
     
iftypeof( parent.window.innerWidth ) == 'number' ) {
          
//Non-IE
          wWidth = parent.window.innerWidth;
          wHeight 
= parent.window.innerHeight;
     }

     
else if( parent.document.documentElement &&
              (parent.document.documentElement.clientWidth 
||
               parent.document.documentElement.clientHeight ) ) 
{
          
//IE 6+ in 'standards compliant mode'
          wWidth = parent.document.documentElement.clientWidth;
          wHeight 
= parent.document.documentElement.clientHeight;
     }

     
else if( parent.document.body && 
              (parent.document.body.clientWidth 
||
                 parent.document.body.clientHeight ) ) 
{
          
//IE 4 compatible
          wWidth = parent.document.body.clientWidth;
          wHeight 
= parent.document.body.clientHeight;
     }

}


// Get Window Location
function GetWindowLocation () {
    
if (!document.layers && document.all) {
          wLeft 
= parent.window.screenLeft;
          wTop 
= parent.window.screenTop;
    }

    
else {
          wLeft 
= parent.window.screenX;
          wTop  
= parent.window.screenY;
    }

}



使用方法如下:
        var params = GetDialogParams(200, 100);
        
var result = window.showModalDialog('url', '', params);


posted on 2007-02-23 17:35  蒜头  阅读(613)  评论(0编辑  收藏  举报

导航