JS Window

JS Tutorial

JS Version

JS Objects

JS Function

JS Classes

JS Async

JS HTML DOM

JS Browser BOM

JS Web API

JS AJAX

JS JSON

JS vs JQUERY

JS Graphics

JS Window

The Browser Object Model (BOM) enables JavaScript to “talk to” the browser.

The Browser Object Model (BOM)

There are no official standards for the Browser Object Model (BOM).

The Window Object

The window object is supported by all browsers. It represents the browser’s window.

All global JavaScript objects, functions, and variables become members of the window object.

Global variables are properties of the window object.

Global functions are methods of the window object.

Even the document object (of the HTML DOM) is a property of the window object:

window.document.getElementById(“header”);

is the same as:

document.getElementById(“header”);

Window Size

Two properties determine the size of the browser window.

Both properties return the sizes in pixels:

window.innerHeight – the inner height of the browser window (in pixels)

window.innerWidth – the inner width of the browser window (in pixels)

<!DOCTYPE html>

<html>

<body>

h2>JavaScript Window</h2>

<p id=”demo”></p>

<script>

document.getElementById(“demo”).innerHTML =

“Browser inner window width: ” + window.innerWidth + “px<br>” +

“Browser inner window height: ” + window.innerHeight + “px”;

</script>

</body>

</html>

Output

JavaScript Window