0

当有人从选择选项中单击相册时,我试图弹出一个窗口。我可以弹出一个新选项卡,但无法弹出一个新窗口并居中。这是我使用过的代码:

function popup(pageURL, title, popupWidth, popupHeight) 
{
    var left = (screen.width / 2) - (popupWidth / 2);
    var top = (screen.height / 2) - (popupHeight / 2);
    var targetPop = window.open(pageURL, title, 'toolbar=no, location=no,directories=no,status=no, menubar=no, scrollbars=YES, resizable=YES, copyhistory=no,width=' + popupWidth + ', height=' + popupHeight + ', top=' + top + ', left=' + left);
}

然后,当您从这样的选择框中选择特定专辑时,我会调用函数 popup():

popup('http://www.google.com', 'googlePopup',700,600)

我使用谷歌只是为了测试目的。

可以用谷歌打开一个窗口,但是它在一个新标签中打开,而不是一个新窗口居中

4

2 回答 2

0

Whether a pop-up opens in a new window or in a new tab depends on user preferences. You cannot change this behavior.

If you want a pop-up that opens center screen, I suggest you use a pure HTML-solution and put a layer on top of your page. You could use a library like jQuery UI for that (or any other available)

于 2013-11-10T10:33:37.670 回答
0

你能试试这个,添加screenXscreenY

  var targetPop = window.open(pageURL, title, 'toolbar=no, location=no,directories=no,status=no, menubar=no, scrollbars=YES, resizable=YES, copyhistory=no,width=' + popupWidth + ', height=' + popupHeight + ', top=' + top + ', left=' + left+",screenX=" + left + ",screenY="
                + top);
于 2013-11-10T10:52:25.133 回答