You can drop window prefix for all the above properties and access it directly as document, navigator, screen, history, and location.
Let’s learn briefly about all the above objects. We will learn about them in greater detail in their dedicated articles.
You can open the browser console(CTRL + SHIFT + J) in this window to run the code examples in this article.
The window object represents the browser’s window containing the web document. It is the root object of the BOM hierarchy. To view properties and objects it contains execute the below code in your browser console.
//window object console.log(window)
The document object represents and returns the reference of the document loaded in the browser’s window.
//title of the loaded document in the window console.log(window.document.title)
The window.navigator object returns the reference to the Navigator Object. Navigator Object contains information about the user agent(browser) and the operating system.
//To get the User-Agent console.log(window.navigator.userAgent)
The window.screen object returns information about the user’s screen.
//get screen width console.log(window.screen.width) //get screen height console.log(window.screen.height)
The window.history returns a reference to the History Object. You can use it for manipulating browser session history(pages visited in the same tab).
// go to previous web page, equivalent to clicking back button window.history.back();
You can get the current page address(URL) or redirect the browser to a new web address using the window. location object.
//current page web address console.log(window.location.href)
We will learn about all the important BOM objects and their properties in another article.
If you liked this article, please upvote and recommend it to show your support. Feel free to ask any questions in the comments below.