我们如何将通过javascript window.open函数打开的弹出窗口置于屏幕变量的中心到当前所选的屏幕分辨率?
以下代码运行良好,并在屏幕上启动Facebook弹出窗口,但此弹出窗口不居中.
<script type="text/javascript">
function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}
Run Code Online (Sandbox Code Playgroud)
<a href="http://www.facebook.com/share.php?u=<full page url to share" onClick="return fbs_click()" target="_blank" title="Share This on Facebook"><img src="images/facebookimage.jpg" alt="facebook share"></a>
Run Code Online (Sandbox Code Playgroud)
以下是以弹出窗口为中心的脚本:
<script type="text/javascript">
function MyPopUpWin(url, width, height) {
var leftPosition, topPosition;
//Allow for borders.
leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
//Allow for title and status bars.
topPosition = (window.screen.height / 2) - ((height / 2) + 50);
//Open the window.
window.open(url, "Window2",
"status=no,height=" + height + ",width=" + width + ",resizable=yes,left="
+ …Run Code Online (Sandbox Code Playgroud) window.open('branchMonitoring/', 'Testing Dual Monitor', 'resizable=1, scrollbars=1, fullscreen=0, height=200, width=650, screenX=0 , left=1280, toolbar=0, menubar=0, status=1');
Run Code Online (Sandbox Code Playgroud)
我使用此代码在第二台监视器上打开了一个新窗口,但新窗口仍在第一台监视器上打开,并且不能超出第一台监视器的边界。我试图将“ left”更改为更高的值,但仍然没有运气。
请兄弟帮我。我正在使用最新的谷歌浏览器和Windows 8双显示器。
请注意,使用FireFox浏览器时,此解决方案对我有效。但是我需要让它在chrome上运行。