Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Window Size

Two properties can be used to determine the size of the browser window:

Both properties return the size in pixels:

  • window.innerHeight – the inner height of the browser window (in pixels)
  • window.innerWidth – the inner width of the browser window (in pixels)
The browser window (or viewport) does not include toolbars or scrollbars.

Example

let w = window.innerWidth;
let h = window.innerHeight;

Other Window Methods

Other useful methods include:

  • window.open() – opens a new window
  • window.close() – closes the current window
  • window.moveTo() – moves the current window
  • window.resizeTo() – resizes the current window