开发者

Show popup in centre of screen/browser

开发者 https://www.devze.com 2023-03-31 13:38 出处:网络
<html> <head> <script lang开发者_C百科uage=\"javascript\" type=\"text/javascript\" >
<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()}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消