<html>
<head>
<script lang开发者_C百科uage="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>
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.
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)
}
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()}
}
精彩评论