如何让JavaScript在当前监视器上打开弹出窗口 [英] How do I get JavaScript to open a popup window on the current monitor

查看:142
本文介绍了如何让JavaScript在当前监视器上打开弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:


  1. 用户有两台显示器。

  2. 他们的浏览器在辅助监视器。

  3. 他们单击浏览器中的一个链接,该链接调用window.open(),其中包含特定的左上窗口偏移。

  4. 弹出窗口窗口总是在他们的主显示器上打开。

  1. The user has two monitors.
  2. Their browser is open on the secondary monitor.
  3. They click a link in the browser which calls window.open() with a specific top and left window offset.
  4. The popup window always opens on their primary monitor.

在JavaScript中是否有任何方法可以让弹出窗口在同一个监视器上打开初始浏览器窗口(开启者)?

Is there any way in JavaScript to get the popup window to open on the same monitor as the initial browser window (the opener)?

推荐答案

您不能指定监视器,但可以指定弹出窗口的位置窗口相对于点击导致窗口弹出的位置。

You can't specify the monitor, but you can specify the position of the popup window as being relative to the where the click caused the window to popup.

使用getMouseXY()函数获取要作为window.open()方法的左箭头和顶箭头传递的值。 (左侧和顶部的args仅适用于V3和更高版本的浏览器)。

Use the getMouseXY() function to get values to pass as the left and top args to the window.open() method. (the left and top args only work with V3 and up browsers).

window.open docs:
http://www.javascripter.net/faq/openinga.htm

window.open docs: http://www.javascripter.net/faq/openinga.htm

function getMouseXY( e ) {
    if ( event.clientX ) { // Grab the x-y pos.s if browser is IE.
        CurrentLeft = event.clientX + document.body.scrollLeft;
        CurrentTop  = event.clientY + document.body.scrollTop;
    }
    else {  // Grab the x-y pos.s if browser isn't IE.
        CurrentLeft = e.pageX;
        CurrentTop  = e.pageY;
    }  
    if ( CurrentLeft < 0 ) { CurrentLeft = 0; };
    if ( CurrentTop  < 0 ) { CurrentTop  = 0; };  

    return true;
}

这篇关于如何让JavaScript在当前监视器上打开弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆