JavaScript Window Properties

About This Index
This page is the JavaScript Window Properties index for the tutorial track. Each row is a value you read on window. There is no separate tutorial file for these properties, so the description lives here.
Learn what the window is on /js/window. Functions such as alert() and setTimeout() are on the methods index.
window.innerWidth is a number. window.closed is true or false. window.innerWidth() throws.
How to Read a Window Property
Properties are values. No parentheses:
window.self === window; // true
window.closed; // false while the tab is open
window.innerWidth; // viewport width
window.scrollY; // pixels scrolled down
window.location.href; // full URL
window.localStorage; // Storage for this origin JavaScript Window Properties Table
Properties you read on window in this JavaScript tutorial (21 entries).
This window and its frames
8 propertiesRead these on window to see which window you are in, and whether it sits inside a frame.
| Property | Description | Guide |
|---|---|---|
self | This window. window.self === window is true. | On this page |
name | The window’s name string. It is "" unless the window or iframe was given a name. | On this page |
closed | false while you can still use the window. true after that window has been closed. | On this page |
opener | The window that called open(), or null when the reader opened this tab. | On this page |
parent | The parent window. On a top-level page, parent === window. | On this page |
top | The topmost window. On a top-level page, top === window. | On this page |
length | How many child frames this window contains. A page with no iframes has length 0. | On this page |
frameElement | The iframe element that contains this window, or null on a top-level page. | On this page |
Size and scroll position
6 propertiesNumbers, in CSS pixels. Read them with no parentheses.
| Property | Description | Guide |
|---|---|---|
innerWidth | Width of the viewport, the area inside the window where the page is drawn. | On this page |
innerHeight | Height of the viewport, the area inside the window where the page is drawn. | On this page |
outerWidth | Width of the whole browser window, including the browser’s own bars. | On this page |
outerHeight | Height of the whole browser window, including the browser’s own bars. | On this page |
scrollX | How many pixels the document is scrolled horizontally. pageXOffset is the same value. | On this page |
scrollY | How many pixels the document is scrolled vertically. pageYOffset is the same value. | On this page |
The page this window shows
7 propertiesObjects the window keeps for the document, the URL, history, and storage.
| Property | Description | Guide |
|---|---|---|
document | The page. window.document is the tree you search with querySelector and getElementById. | On this page |
location | The URL of this window. location.href is the full address. Assigning it navigates the page. | On this page |
history | The session history for this tab. history.back() goes to the previous entry. | On this page |
navigator | The browser. navigator.userAgent is one string it exposes. | On this page |
screen | The display. screen.width and screen.height are the screen size in pixels. | On this page |
localStorage | A Storage object for this origin that keeps keys after the tab closes. | On this page |
sessionStorage | A Storage object for this origin that lasts until this tab closes. | On this page |
Frequently Asked Questions
Call a method next
Properties are values. alert() and setTimeout() are functions.
11 people found this page helpful
