Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I move a window's position on the computer screen with 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?

like image 857
Matrym Avatar asked Oct 20 '11 20:10

Matrym


People also ask

How do I move a window in JavaScript?

JavaScript allows you to move a window either relatively (by the amount specified), or absolutely (to the coordinates on the screen specified). For your convenience, here are the related window methods again: - moveBy () method Use moveBy () to move a window either horizontally, vertically, or both, by the specified amount in pixels.

How do I move a program to the side of my screen?

Select Move from the pop-up menu. Press the left arrow or right arrow key until the program or app appears on the screen. A similar method swaps out the Shift key for the Windows key. It also relies on the snapping feature that snaps windows to the sides of your screen.

How to move a window in Windows 10 with keyboard?

Step 1: Click the window or you can use the keyboard shortcut – Alt + Tab and let the window that you want to move active. Step 2: Then, press Alt + Spacebar and you can see a small menu Step 3: Press M (equal to selecting the Move option) and the mouse cursor will turn into a cross with arrows and move to the title bar of the window.

How to move a window that is off-screen in Windows 11?

Again, use the Left or Right arrow keys on the keyboard to shift the off-screen window on the desktop fully. This method too can work if you’re still wondering how to move a window that is off-screen in Windows 11 if the window is still visible in the Taskbar.


1 Answers

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

Courtesy of @Dan Herbert:

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.

like image 159
James Johnson Avatar answered Oct 13 '22 05:10

James Johnson