Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript Window

JavaScript Window - Browser Object Model


The Browser Object Model (BOM) enables JavaScript to "talk" with the browser.


Browser Object Model (BOM)

Browser Object Model (Browser Object Model (BOM)) has no formal standard yet.

Since modern browsers have (almost) implemented the same methods and properties for JavaScript interaction, these are often considered BOM methods and properties.


Window Object

All browsers support the window object. It represents the browser window.

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

Global variables are properties of the window object.

Global functions are methods of the window object.

Even the HTML DOM document is one of the properties of the window object:

window.document.getElementById("header");

The same as:

document.getElementById("header");


Window size

There are three ways to determine the size of the browser window.

For Internet Explorer, Chrome, Firefox, Opera, and Safari:

For Internet Explorer 8, 7, 6, 5:

or

A practical JavaScript solution (covering all browsers, including IE8 and below):

Example

var

w

=

window

.

innerWidth

||

document

.

documentElement

.

clientWidth

||

document

.

body

.

clientWidth

;

var

h

=

window

.

innerHeight

||

document

.

documentElement

.

clientHeight

||

document

.

body

.

clientHeight

;

Try it »

This example displays the height and width of the browser window.


Other Window methods

Some other methods: