By: aathishankaran in JavaScript Tutorials on 2007年04月02日 [フレーム]
In JavaScript, the window object represents the browser window or frame in which the current web page is displayed. It provides properties and methods for controlling the browser window or frame, as well as accessing the document object and other objects associated with the current web page.
Here are some examples of using the window object in JavaScript:
Accessing the current URL:
console.log(window.location.href);
Opening a new window:
The window Attributes parameter is important as you display windows because it lets you customize the look of the window you are opening. The window Attributes parameter is optional; not including it gives you a window identical to the current one with respect to attributes.
Attribute
Description
width
Width of window in pixels
height
Height of window in pixels
toolbar
Show/hide browser toolbar
Menubar
Show/hide browser menu bar
Scrollbars
Show/hide browser horizontal and vertical scrollbars
resizable
Allow/disallow resizing of browser window
Status
Show/hide browser status bar
Location
Show/hide URL location box
Directories
Show/hide secondary toolbar (Netscape)
Copyhistory
Copy current window's Go history for new window
window.open('https://www.example.com', '_blank');
Closing the current window:
window.close();
Displaying an alert box:
window.alert('Hello, world!');
Setting the title of the current page:
window.document.title = 'My Page Title';
Getting the height and width of the browser window:
console.log('Height: ' + window.innerHeight + ', Width: ' + window.innerWidth);
Redirecting to a new URL:
window.location.href = 'https://www.example.com';
These are just a few examples of how the window object can be used in JavaScript. There are many other properties and methods available on the window object, which can be useful for building dynamic and interactive web applications.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in JavaScript )
Dynamically modify the option set in Dynamics 365 forms
promise and .then() in JavaScript
reduce() and filter() in JavaScript
History and evolution of Javascript
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
Show how many characters remaining in a html text box using javascript
Latest Articles (in JavaScript)
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate