You are here: Reference > JavaScript > client-side > browser > properties > screenX (window)

screenX property (window)

Browser support:
9
Returns an integer value that indicates the horizontal position of the left side of the browser window, relative to the left side of the screen.
Note: The screenX property is supported in Internet Explorer from version 9.
The screenX property retrieves wrong value in Opera. There is no property or method in JavaScript to get the position of the top-left corner of the browser window in Opera and Internet Explorer before version 9.
If you need the position of the left side of the browser's client area, use the screenLeft property.
The screenX and screenLeft properties are equivalent in Google Chrome and Safari, they return the horizontal position of the left side of the browser window.
  • To get the top position of the browser window, use the screenY property.
  • If you need the size of the browser window, see the pages for the outerHeight and outerWidth properties.
  • The browser window can be resized with the resizeBy and resizeTo methods,
  • and can be moved with the moveBy and moveTo methods.
If you need information about the dimensions of the screen, use the screen object.

Syntax:

object.screenX;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Integer that represents the x-coordinate of the left side, in pixels.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the screenX property:
<head>
    <script type="text/javascript">
        function UpdatePos () {
            var message = "";
            if ('screenLeft' in window) {
                message += "Client area: " + window.screenLeft + "px, " + window.screenTop + "px<br/>";
            } 
            if ('screenX' in window) {
                message += "Browser window: " + window.screenX + "px, " + window.screenY + "px";
            }

            var info = document.getElementById ("info");
            info.innerHTML = message;
        }
    </script>
</head>
<body onload="UpdatePos ()">
    <b>Left, top positions:</b>
    <div id="info" style="height:65px; width:250px; background-color:#e0a0a0;"></div>
    <button onclick="UpdatePos ();">Update positions!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content