1. 程式人生 > >計算當前螢幕大小js

計算當前螢幕大小js

   在後臺頁面中,計算彈出框的大小,需用到當前螢幕的大小。

/*螢幕尺寸計算*/

function getPageSize(){
   var screen_height = window.screen.availHeight; 
   var screen_width = window.screen.availWidth; 
   return new Array($(document).width(),$(document).height(),$(window).width(),$(window).height(),screen_width,screen_height);
}
根據螢幕尺寸計算彈出框大小:
//需彈出的頁面
function vopen(url, name, w, h) {   //if (! OWinID || OWinID.closed)
    if(w==null||w==""){w=800;}
    if(h==null||h==""){h=500;}
    var top,left;
    var pws = getPageSize();
    top=(pws[5]-h)/2 -20;  //pws[5]==screen_height;
    left=(pws[4]-w)/2;
   OWinID = window.open(url, name, "height=" + h + ",width=" + w + ",top="+top+",left="+left+",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=yes");
OWinID.focus();
}