JavaScript Window screenLeft property

The JavaScript Window screenLeft property is a read-only property that returns the horizontal position of the current window relative to the user’s screen. It is commonly used to determine the position of the window on the screen, or to move the window to a specific location.

Here are some examples of how the screenLeft property can be used in JavaScript code:

  1. To retrieve the horizontal position of the current window, you can use the following code:
var left = window.screenLeft;

// the value of left will be the horizontal position of the window
  1. To move the current window to a specific horizontal position, you can use the following code:
// calculate the new position of the window
var left = (window.screen.availWidth - window.outerWidth) / 2;
var top = window.screenTop;

// move the window to the calculated position
window.moveTo(left, top);
  1. To center the current window on the screen, you can use the following code:
// calculate the position of the window
var left = (window.screen.availWidth - window.outerWidth) / 2;
var top = (window.screen.availHeight - window.outerHeight) / 2;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: