How to move window position on computer screen using javascript?

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

+4
source share
4 answers

I do not know how reliable this is, but to move the window relative to the 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 a window to a specific 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

Provided by @ Dan Herbert:

It should probably be noted that window.moveTo(0,0) move to the upper left corner of the main screen. For people with multiple monitors, you can also send negative coordinates to a position on another monitor. You can check that the second monitor goes to screen.availLeft . If it is negative, you can move the window, which is far to the second monitor.

+5
source

From Google Quick Search: Moving Windows

You are looking for Window.moveBy and window.moveTo

I also remember this video, you choose your hometown and much more? I really enjoyed it.

+1
source

You move the displayed position of the object by changing its upper and left margins, which together represent the coordinates of the upper left corner. If you know the absolute coordinates of the target position, you can change the fields and the object will move to this place.

If you donโ€™t know the absolute target position, but only two relative deltas (i.e. move the window by 5 pixels and the right 10 pixels), you can read the upper and left fields of the object, increase their distances accordingly and set the fields for this.

Fields are part of the style of the object, so you can say something like:

  theobject.style.left = 10 + 'px'; theobject.style.top = 40 + 'px'; 

for a positioned object.

0
source

Since your links contain anchors, the "#" when you click on the links, it will move the page back. Try replacing href with something like:

 href="javascript:void(0)" 

This will prevent the execution of anything inside href.

0
source

All Articles