JavaScript Window Object
The Window object is the top-level object in client-side JavaScript. It represents the web page or browser window that is currently active and provides a wide range of properties and methods for browser interactions.
Syntax
window.propertyName;
window.methodName();
Example
// Get the browser's name and version
var browserName = window.navigator.appName;
var browserVersion = window.navigator.appVersion;
// Open a new window
window.open("https://www.google.com", "Google", "width=800,height=600");
// Display an alert message
window.alert("Hello, world!");
Output
The output of the above example code will be:
browserName
will contain the name of the user's browser (e.g. "Netscape" or "Microsoft Internet Explorer").browserVersion
will contain the version of the user's browser (e.g. "5.0 (Windows; en-US)").- A new window with Google's website will open with a width of 800 pixels and a height of 600 pixels.
- An alert message with the text "Hello, world!" will be displayed on the page.