window.open() on a multi-monitor/dual-monitor system - where does window pop up?

前端 未结 7 776
执笔经年
执笔经年 2020-11-29 23:03

When using javascript window.open() on a multi-monitor system, how do you control which monitor, or where in the display space the popup opens? It seems out of control to me

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 23:34

    window.screenX will give the position of the current monitor screen.

    suppose monitor width is 1360

    for monitor 1 window.screenX = 0;

    for monitor 2 window.screenX = 1360;

    so by adding left position with window.screenX, popup open in expected position.

    function openWindow() {
    
        var width = 650;
        var left = 200;
    
        left += window.screenX;
    
        window.open(thePage,'windowName','resizable=1,scrollbars=1,fullscreen=0,height=200,width=' + width + '  , left=' + left + ', toolbar=0, menubar=0,status=1');    
        return 0;
    
    }
    

提交回复
热议问题