JavaScript is partly an object-oriented language.

To learn JavaScript, we got to learn the object-oriented parts of JavaScript.

In this article, we’ll look at the built-in properties of window .

The window.screen Property

The window.screen property lets get information about the browser’s screen.

We can get the color depth with:

window.screen.colorDepth;

And we can get the screen’s width with:

screen.width;
screen.availWidth;

width is the whole screen and availableWidth subtracts the widths of the menus and scrollbars, etc.

We can get the heights the same way with:

screen.height;
screen.availHeight;

Some devices also have the devicePixelRatio property:

window.devicePixelRatio

which tells us the trio between the physical pixels and device pixels in retina displays.

window.open()/close() Method

The window.open method lets us open a new browser window.

Various policies and settings of the browser may prevent us from opening popups to curb popup ads.

But we should be able to open a new window if it’s initiated by the user.

If we try to open a window when the page loads, it’ll probably be blocked since the user didn’t open the window.

The window.open() method takes a few parameters.

The first is the URL to load in a new window.

The name of the new window can be used as the value of the form’s target attribute.

A comma-separated list of features are also arguments, which include resizable to indicates whether the popup is resizable.

The width is the width of the popup window.

status is indicates whether the status bar should be visible.

For instance, we can write:

const win = window.open('http://www.example.com', 'example window',
'width=300,height=300,resizable=yes');

We call the open method with the URL, the title, and a string with the window size and whether it’s resizable.

win has the close method to let us close the window.

#technology #programming #javascript

Object-Oriented JavaScript — Properties of Window
1.30 GEEK