You are here: Reference > JavaScript > client-side > browser > methods > moveBy (window)

moveBy method (window)

Browser support:
Moves the browser window by the specified number of pixels, relative to its current coordinates.
  • To move the browser window to a specified position relative the top-left corner of the screen, use the moveTo method.
  • The browser window can be resized with the resizeBy and resizeTo methods.
  • To get the size and the top-left corner of the browser window, use the outerWidth, outerHeight and the screenX, screenY properties.
  • If you need information about the dimensions of the screen, use the screen object.

Syntax:

object.moveBy (X, Y);
You can find the related objects in the Supported by objects section below.

Parameters:

X
Required. Integer that specifies the horizontal offset, in pixels. Negative values are also allowed.
Y
Required. Integer that specifies the vertical offset, in pixels. Negative values are also allowed.

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the moveBy method:
<head>
    <script type="text/javascript">
        document.onkeydown = MoveWindow;

        function MoveWindow (event) {
            if (!event) {
                event = window.event;
            }
            var keyCode = event.which ? event.which : event.keyCode;
            switch (keyCode){
                case 39:
                    window.moveBy (15, 0);
                    break;
                case 37:
                    window.moveBy (-15, 0);
                    break;
                case 38:
                    window.moveBy (0, -15);
                    break;
                case 40:
                    window.moveBy (0, 15);
                    break;
            }
        }
    </script>
</head>
<body>
    Use the arrow keys on your keyboard to move the browser window!
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content