window.moveBy

In this chapter you will learn:

  1. How to move a window with Javascript
  2. How use negative value to move window to left

window.moveBy(distance, distance)

The following code moves a windows by 100 pixels.

<!DOCTYPE HTML> <!--from j a  va 2s .com-->
<html> 
    <head> 
        <title>Example</title> 
    </head> 
    <body> 
        <script type="text/javascript"> 
            
            //move the window down by 100 pixels 
            window.moveBy(0, 100); 

        </script> 
    </body> 
</html>

Click to view the demo

Move left

The following code moves window to the left.

<!DOCTYPE HTML> <!--   j  a  v  a  2s . c om-->
<html> 
    <body> 
        <script type="text/javascript"> 
            
            //move the window left by 50 pixels 
            window.moveBy(-50, 0); 

        </script> 
    </body> 
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. How to move a window to a new location in Javascript
Home » Javascript Tutorial » Window
Window Object
alert()
close()
confirm()
find()
Window height and width
location
window.moveBy
window.moveTo
window.open()
window.print()
window.prompt()
resizeTo(x,y) and resizeBy(xDelta,yDelta)
window.scrollTo(x,y)
screenLeft, screenX, screenTop, screenY
setInterval()
setTimeout()