2013-09-24 49 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