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

前端 未结 7 788
执笔经年
执笔经年 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 23:48

    A javascript-based solution does not work because of security reasons.

    I have another idea for you, why not use a chrome extension for handling the positioning. (no security problem there) It is of course, only for chrome(maybe thats fine for you).

    Background: We had related difficulties. Internal webapp that opens multiple documents in windows, and need to be placed in other monitors. The javascript does not support this, for security reasons and only a native extension can properly work with the tabs/windows objects.

    Therefore, we have created an open source chrome extension for doing exactly that: flexible windows position across multi-monitor setups.

    In your case you could easily define a rule per monitor where and how it would appear. You can do it in the options page of the chrome extension. (as shorcut you can, after installation, go directly there using)

    The chrome extension is called "MultiWindow Positioner" and its complete free. You can get it at the chrome store here

    The actual source code you find in github in the project chrome-multiwindow-positioner

    Disclaimer: I am the maintainer of the open source (MIT) github project. If there any interesting idea, or comments feel free to share them here.

    UPDATE 21/09/2020 I'm no longer maintainer of the open source project as I left that company. That said, I don't understand the downvotes, the browsers do not provide window.APIs that allow you to cleary understand multiple monitors because its a clear security restriction/violation. Thats where browser plugin extensions help, as they are not a webpage they get access to additional APIs that allow exactly to find/list monitors and windows. They follow a different security context, and therefore the additional power. Not all browsers offer the require extension.APIs for mutlmonitor support. Mozilla Firefox mostly does not. Chrome and latest MS Edge yes. After so many years of experience, I'm still 100% there is NO plain javascript solution, and the only way is a solution that involves a browser plugin/extension.

提交回复
热议问题