JavaScript Window object has useful properties. All data and information about any browser are attached to the window object as properties. We can access window object’s properties like.
The properties of a window object are used to retrieve the information about the window.
window.propertyname
Here is a table of the most popular window object properties is given below:
Property | Description |
---|---|
closed | returns a boolean value that specifies whether a window has been closed or not |
document | specifies a document object in the window. |
history | specifies a history object for the window. |
frames | specifies an array of all the frames in the current window |
defaultStatus | specifies the default message that has to appear in the status bar of Window. |
innerHeight | specifies the inner height of the window’s content area. |
innerWidth | specifies the inner width of the window’s content area. |
length | specifies the number of frames contained in the window. |
location | specifies the location object for the window |
name | specifies the name of the window |
top | specifies the reference of the topmost browser window. |
self | returns the reference of the currently active frame or window. |
parent | returns the parent frame or window of the current window. |
status | specifies the message that is displayed in the status bar of the window when an activity is performed on the Window. |
screenleft | specifies the x coordinate of the window relative to a user’s monitor screen |
screenTop | Specifies the y coordinate of the window relative to a user’s monitor screen |
screenX | specifies the x coordinate for the window relative to a user’s monitor screen |
screenY | Specifies the y coordinate for window relative to a user’s monitor screen |
Window object properties in JavaScript
Simple example code.
<!DOCTYPE html>
<html>
<body>
<button onclick="createWindow()">Open a Window</button>
<script>
function createWindow() {
var win = window.open("", "My Window", "width=500, height=200,screenX=100,screenY=100");
// window properties
var isclose = win.closed;
var name = win.name;
console.log(isclose);
console.log(name);
console.log(win.screenY);
console.log(win.screenX);
// we can access the new window document like this
win.document.write("Hello World!");
}
</script>
</body>
</html>
Output:
Do comment if you have any doubts or suggestions on this JS window object topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version