JAVASCRIPT Tutorial

JS Window

Key Concepts:

  • Window Object: The window object represents the browser window and provides access to its properties and methods.
  • Global Object: In the browser's JavaScript environment, the window object acts as the global object, containing globally available variables and functions.
  • Window Properties: Properties of the window object provide information about the browser window, such as its dimensions, scroll position, and history.
  • Window Methods: Methods of the window object allow you to interact with the browser window, such as opening and closing dialogs, setting timers, and triggering events.
  • Browser Window: The browser window is the interface through which users interact with the web page. It includes components like the address bar, menu bar, and scrollbars.

Understanding the Window Object:

The window object is accessible through the window variable. It provides a wealth of information and functionality related to the browser window.

  • Properties: Some important properties include:
    • window.innerHeight: Height of the window in pixels.
    • window.location: Object representing the current URL and its components.
    • window.history: Object providing access to the browser's history.
  • Methods: Some useful methods include:
    • window.open(): Opens a new browser window or tab.
    • window.alert(): Displays a message dialog.
    • window.setInterval(): Sets a timer that repeatedly calls a function.

Example:

// Get the current URL
console.log(window.location.href);

// Open a new window
window.open("https://www.example.com", "_blank");

// Set a timer to run a function every second
window.setInterval(() => {
  console.log("Time passed...");
}, 1000);

Tips for Accessibility and Ease of Use:

  • Use the window.accessible property to check if the user has enabled accessibility features in their browser.
  • Provide alternative text for images using the window.altText property.
  • Use the window.caption property to set a title for the browser window.