Last Updated On By Khizer Ali
Table of Contents
A window object is the browser’s window. When you open tabs in a browser, each tab will have its own window object where all the components, functions and objects will become part of the window. The object will have properties, functions and variables just like any other object. All the global variables and function will become the object’s variable and functions. Let’s discuss JavaScript window Objects
JavaScript is object oriented. Even though it’s a bit different then typical object oriented language like C#, or c++. JavaScript has a bit different and interesting concepts of classes and objects, it supports objects without implementing classes.
A document object is where all the html tags are portrayed and combined into a document like frame. In pages, all objects are part of hierarchy. Window’s object is the top most in the hierarchy and everything is a part of it. When all the parts get loaded into the window, the document will have all the HTML tags.
The window object gives you information about the current window being used. This information is required most frequently in development. information like the current location, URL, present directory or path etc.
Here are some most used properties of a window object.
You can use these properties using a dot or access operator(.). for example,
Following are the most frequently used functions of a window object.
closed | Returns true or false if a window is closed or not |
console | Returns a reference to the Console object. |
innerHeight | Returns the height of the window |
outerHeight | Returns the outer height of the browser window. |
outerWidth | Returns the outer width of the browser window. |
localStorage | Allows to save key/value pairs in a web browser. |
document | Returns the Document object for the window. |
history | Returns the History object for the window |
parent | Returns the parent window of the current window |
status | Sets or returns the text in the status bar of a window |
location | Returns the Location object for the window |
name | Sets or returns the name of a window’s content. |
innerHeight | Returns the height of the window’s content. |
innerWidth | Returns the width of a window’s content area (viewport) including scrollbars |
length | Returns the length of the elements in the window |
You can use these properties using a dot or access operator(.). for example,
The following are the most frequently used functions of a window object.
alert() | Displays an alert box with a message and an OK button |
blur() | Removes focus from the current window |
close() | Closes the current window |
confirm() | Displays a dialog box with a message and an OK and a Cancel button |
focus() | Sets focus to the current window |
getComputedStyle() | Gets the current computed CSS styles applied to an element |
open() | Opens a new browser window |
print() | Prints the content of the current window |
print() | Prints the content of the current window |
prompt() | Displays a dialog box that prompts the visitor for input |
stop() | Stops the window from loading |
Just like properties you can use dot or access operator to access the built in functions to retrieve different type of information
JavaScript window’s object helps in better understanding of how the html is loaded into a window and being targeted and manipulated to get the desired outcome. Windows object gives all the information for the window of the browser.