<html>
<head>
<script language="javascript" type="text/javascript" >
function popupwindow(url, title, w, h)
{
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var new_left = window.screenX + (((window.outerWidth/2) - (w/2)));
var new_top = window.screenY + (((window.outerHeight/2) - (w/2)));
return window.open(url, title, 'width='+w+', height='+h+', top='+new_top+', left='+new_left+',toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no');
}
popupwindow('index.html','','1024','768');
</script>
</head>
<body>
</body>
<html>
Asked
Active
Viewed 4,472 times
0

Cameron
- 27,963
- 100
- 281
- 483
-
possible duplicate of [Center a popup window on screen?](http://stackoverflow.com/questions/4068373/center-a-popup-window-on-screen) – epascarello Aug 30 '11 at 12:04
3 Answers
1
Look at what you posted
newwindow = window.open('index.html','_blank', 'top=0,left=0,width=1024,height=768,top='+centeredY+',left='+centeredX+'');
You have top=0,left=0
and top='+centeredY+',left='+centeredX
Why do you have it twice?
Also the code is not cross browser friendly.

epascarello
- 204,599
- 20
- 195
- 236
0
You have specified top and left values more than once in your argument list
function popup()
{
newwindow = window.open('index.html','_blank', 'top=0,left=0,width=1024,height=768,top='+centeredY+',left='+centeredX+'');
^^^^^^^^^^^^^
if (window.focus) {newwindow.focus()}
}

Fabio
- 18,856
- 9
- 82
- 114
-
Try to inspect the `centeredX` and `centeredY` values with `console.log(centeredX);` or `alert(centeredX)` just before your `window.open` call. On Chrome it gives me undefined. – Fabio Aug 30 '11 at 12:06
0
You can do this using following code :
function centerWindow() {
leftPos = 0
topPos = 0
if (screen) {
leftPos = (screen.width / 2) - 251
topPos = (screen.height / 2) - 162
}
ElementWindow = window.open('index.html','_blank',
'width=502,height=325,left='+leftPos+',top='+topPos)
}

Tushar Ahirrao
- 12,669
- 17
- 64
- 96