BOM Browser Object Model Window moveBy and moveTo Method tutorial in JavaScript

 <!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>BOM moveBy moveTo Method JavaScript</title>
</head>

<body>
    <!--JS Window moveBy()
The moveBy() method moves a window a number of pixels relative to its current coordinates.
Syntax :
window.moveBy(x, y)

JS Window moveTo()
The moveTo() method moves a window to the specified coordinates.
Syntax :
window.moveTo(x, y)

Main Difference between moveTo() and moveBy() is that moveTo() works on absolute position and moveBy() works on relative position-->
    <button onclick="openWindow()">Open Window</button>
    <button onclick="moveToWindow()">MoveTo window</button>
    <button onclick="moveByWindow()">MoveBy Window</button>
    <script>
        var myWindow;
        function openWindow() {
            myWindow = window.open("", "_blank", "width=500px,height=200px,left=100px,top=100px");
            myWindow.document.write("<p>This is myWindow.</p>");
        }
        function moveToWindow() {
            myWindow.moveTo(200, 200);
            myWindow.focus();
        }

        function moveByWindow() {
            myWindow.moveBy(200, 200);
            myWindow.focus();
        }
    </script>
</body>

</html>


Comments

Popular posts from this blog

Symbols tutorial in Advance JavaScript

Async and Await Method tutorial in Advance JavaScript

String Methods in JavaScript