如何使用javascript在计算机屏幕上移动窗口的位置?

如何使用javascript在计算机屏幕上移动窗口的位置?

问题描述:

我记得看过一个谷歌地图mashup /音乐视频,它在屏幕上创建,调整大小和移动窗口。使用了哪些javascript方法?

I remember seeing a google maps mashup / music video that created, resized, and moved windows on the screen. What javascript methods are used to do this?

我不知道这是多么可靠,但要相对移动窗口到目前的位置你可以这样做:

I don't know how reliable this is, but to move the window relative to it's current position you can do this:

window.moveBy(250, 250); //moves 250px to the left and 250px down

http://www.w3schools.com/jsref/met_win_moveby.asp

要将窗口移动到屏幕的某个部分:

To move the window to a certain part of the screen:

window.moveTo(0, 0); //moves to the top left corner of the screen (primary)

http://www.w3schools.com/jsref/met_win_moveto.asp

由@Dan Herbert提供:

Courtesy of @Dan Herbert:


应该注意 window.moveTo(0, 0)将移动到主屏幕左上角的
。对于拥有多个
监视器的人,您还可以将负坐标发送到另一个
监视器上的位置。您可以使用
screen.availLeft 来检查第二台显示器。如果它是负数,你可以将一个远远超过
的窗口移动到第二台显示器上。

It should probably be noted that window.moveTo(0,0) will move to the top left corner of the primary screen. For people with multiple monitors you can also send negative coordinates to position on another monitor. You can check for a second monitor to move to with screen.availLeft. If it's negative, you can move a window that far onto the second monitor.