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

前端 未结 7 789
执笔经年
执笔经年 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:45

    Here is a solution:

    function openWindow( url, winnm, options)
    {
        var wLeft = parseInt( typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft );
    
        var left = 0;
    
        if( (result = /left=(\d+)/g.exec(options)) ) {
            left = parseInt(result[1]);
        }
    
        if(options)
        {
           options = options.replace("left="+left,"left="+(parseInt(left) + wLeft));        
           w = window.open( url, winnm, options );
        }
        else
        {
           w = window.open( url, winnm );
        }
    
        if(w)
             w.focus();
    
        return w;
    }
    

    You just need to replace in your js files: window.open to openWindow

提交回复
热议问题