2012-04-30 75 views
2

我正在使用這樣的JQuery UI對話框;設置窗口彈出座標

$(function() { 
     var dlg = $("#dialog").dialog({ 
      draggable: true, 
      resizable: false, 
      width: 950, 
      height: 480, 
      autoOpen: false, 
      modal: true, 
      minHeight: 30, 
      minwidth: 30, 
      title: 'test' 
     }); 
    }); 

窗口:

function PopupUrl(url, name, width, height) { 
     var features = "location=1, status=1, scrollbars=1, width=" + width + ", height=" + height + '"'; 
     window.open(url, name, features); 
    } 

對話框打開頁面的中心,但彈出出現不同的座標。我想重疊。這個怎麼做?

回答

2

只需添加一個計算的頂部和左側您的功能列表,並彈出將被定位在屏幕的中心:

function PopupUrl(url, name, width, height) { 
    var top = parseInt((screen.availHeight/2) - (height/2)); 
    var left = parseInt((screen.availWidth/2) - (width/2)); 
    var features = "location=1, status=1, scrollbars=1, width=" + width + ", height=" + height + ", top=" + top + ", left=" + left; 
    window.open(url, name, features); 
}