Objects: window, document, location, history
In JavaScript, there are several global objects that allow interaction with the browser and the web document. These objects are window, document, location, andhistory.
Details:
- window: Represents the browser window.
Example:
console.log(window.innerWidth);
- document: Represents the HTML document's DOM tree.
Example:
document.getElementById("myButton").addEventListener("click", function() { alert("Hello!"); });
- location: Contains information about the current URL.
Example:
console.log(location.href);
- history: Provides access to the browser's history.
Example:
history.back();
Purpose:
Understanding global JavaScript objects like window, document, location, and historyis fundamental for interacting with the browser and manipulating DOM elements, as well as for developing dynamic and efficient web applications.
Exercises
The rest of the content is available only for registered and premium users!
JavaScript Concepts and Reference
Functions
Objects in JavaScript
Arrays
DOM (Document Object Model)
Error Handling
Promises and Asynchronicity
Modules in JavaScript
ES6 and Advanced Features
Window history pushState Document location vs window location Window history list Document location origin JS window history History location javascript Document location reload Script window location