window.open 居中打开页面和 刷新父窗体

<html>
<head>
<SCRIPT language=javascript type=text/javascript>
/*
改造window.open函数,保证所有窗口居中弹出,并指定固定的几种窗口大小.以统一系统中的操作风格.

url        --   弹出窗口路径
sTiltle    --  窗口标题
sSize     --  窗口型号,可以自己再增加
*/
var nwin;      
function openwindow(url,sTitle,sSize)      
{      
    if (url==''){
      return false;
    }

    if (nwin && !nwin.closed){      
       nwin.close();      
    }      
  

    if (sSize == undefined) {
       alert("请指定窗口型号!");
       return false;
    }
    else if (sSize == 100) {
       sWidth  = screen.availWidth;
       sHeight = screen.availHeight;
    }

   else if (sSize == 1) {
       sWidth  = 280;
       sHeight = 120;
    }
    else if (sSize == 2) {
       sWidth  = 600;
       sHeight = 400;
    }

    var l = ( screen.availWidth - sWidth ) / 2;
    var  t = ( screen.availHeight - sHeight ) / 2;      

     
    nwin = window.open(url,sTitle,'left=' + l +',top=' + t 

+',width='+sWidth+',height='+sHeight+',scrollbars=yes,resizable=yes');      
    nwin.focus();      
}
</script>
</head>

<body>
  
  <a href=javascript:openwindow("http://www.sina.com","试验窗口",100);>弹出100号窗口  -- 满屏窗口</a><BR>
  <a href=javascript:openwindow("http://www.sina.com","试验窗口",1);>弹出1号窗口  280*120</a><BR>
  <a href=javascript:openwindow("http://www.sina.com","试验窗口",2);>弹出2号窗口  罘*400</a><BR>
  <a href=javascript:openwindow("http://www.sina.com","试验窗口");>不指定窗口型号</a><BR>
</body>
</html>
 
 
 
刷新父窗体:
 
 
window.opener.location.reload();
 
 
居中显示
 
<Script language="javascript" type="text/javascript">
function openwindow(url,name,iWidth,iHeight)
 {
  var url;                                 //转向网页的地址;
  var name;                           //网页名称,可为空;
  var iWidth;                          //弹出窗口的宽度;
  var iHeight;                        //弹出窗口的高度;
  var iTop = (window.screen.availHeight-30-iHeight)/2;       //获得窗口的垂直位置;
  var iLeft = (window.screen.availWidth-10-iWidth)/2;           //获得窗口的水平位置;
  window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
 }
</Script>
调用方法为:<a href="JavaScript:openwindow('Url.html','NewWin','200','200')">点击</a>
posted @ 2008-08-25 09:39  海底的鱼  阅读(6468)  评论(0)    收藏  举报