Master AI & Build your First Coding Portfolio with SkillReactor | Sign Up Now

Lesson 3 - Browser BOM

3.1 JS Window

The window object provides methods and properties to control the browser window. All global JavaScript objects, functions, and variables automatically become members of this window object.

Here are some common window properties and methods:

  • window.alert(): Displays an alert dialog with a message.
alert('Hello, world!');
  • window.console: Provides access to the browser's console for logging information.
console.log('This is a log message.');
  • window.innerHeight and window.innerWidth: Get the inner height and width of the window.
const height = window.innerHeight;
const width = window.innerWidth;
console.log(`Height: ${height}, Width: ${width}`);
  • window.open(): Opens a new browser window or tab.
window.open('https://www.example.com', '_blank');
  • window.close(): Closes the current window.
window.close();

These examples demonstrate how to use various window object properties and methods in JavaScript to interact with the browser window and its environment.