The window
object in JavaScript is the top-level object that represents the current browser window or tab. It provides access to many properties and methods that are related to the window, including the size, position, and state of the window, as well as methods for interacting with the document, opening and closing windows, and managing the history of the browser.
Here are some examples of how to use the window
object:
- Get the size of the window:
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
console.log("Window size: " + windowWidth + " x " + windowHeight);
In this example, the innerWidth
and innerHeight
properties of the window
object are used to get the width and height of the window, respectively.
- Open a new window:
window.open("https://www.example.com", "ExampleWindow", "width=400,height=300");
In this example, the open
method of the window
object is used to open a new window with a specified URL, name, and size.
- Change the location of the current window:
window.location.href = "https://www.example.com";
In this example, the href
property of the location
object is used to change the location of the current window to a new URL.
These are just a few examples of how to use the window
object. There are many other properties and methods available on the window
object, and you can find more information about them in the JavaScript documentation.
+ There are no comments
Add yours