2013-09-24 48 views
1

我有一個動態傳遞的Div數據。 我想在某些事件觸發後在彈出窗口中打開該div數據。 我完成了我的代碼。但是,當彈出在我的瀏覽器是開放的不居中對齊。其在角落未來..Window.popup在瀏覽器中居中對齊

我的代碼: -

 var w = 620; 
     var h = 360; 
     var left = (screen.width/2)-(w/2); 
     var top = (screen.height/2)-(h/2); 
     var divText = document.getElementById("inviteConfirmationMessage").outerHTML; 
     var myWindow = window.open('','','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left); 
     var doc = myWindow.document; 
     doc.open(); 
     doc.write(divText); 
     doc.close(); 

在Mozilla Firefox工作,但在Chrome中不工作 -

http://jsfiddle.net/Wj3Qk/2/

請幫我!或任何指導。

+0

可能重複(http://stackoverflow.com/questions/5681415/how-to-center-彈出窗口) – epascarello

回答

3
var left = (window.screen.width/2) - ((w/2) + 10); 
    var top = (window.screen.height/2) - ((h/2) + 50); 

window.open('','', 
    "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" 
    + left + ",top=" + top + ",screenX=" + left + ",screenY=" 
    + top + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no"); 
+0

感謝您的幫助。但它不工作..我檢查。我的流行在拐角處開有高度和寬度相同 –

+0

Neeraj 我用這個代碼,並將其打開彈出式在中心

+0

Aniket它不工作我檢查 –

-2
var myWindow = window.open('','','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left); 

您錯過了最後一個報價。

是應該是這樣的:?如何中心的彈出窗口]

var myWindow = window.open('','','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left+'); 
+0

它不會是..我已經檢查過...語法錯誤 –

+0

哇,這是錯誤的!你剛剛創建了一個語法錯誤。 – epascarello