Skip to content

Window object properties in JavaScript

  • by

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:

PropertyDescription
closedreturns a boolean value that specifies whether a window has been closed or not
documentspecifies a document object in the window.
historyspecifies a history object for the window.
framesspecifies an array of all the frames in the current window
defaultStatusspecifies the default message that has to appear in the status bar of Window.
innerHeightspecifies the inner height of the window’s content area.
innerWidthspecifies the inner width of the window’s content area.
lengthspecifies the number of frames contained in the window.
locationspecifies the location object for the window
namespecifies the name of the window
topspecifies the reference of the topmost browser window.
selfreturns the reference of the currently active frame or window.
parentreturns the parent frame or window of the current window.
statusspecifies the message that is displayed in the status bar of the window when an activity is performed on the Window.
screenleftspecifies the x coordinate of the window relative to a user’s monitor screen
screenTopSpecifies the y coordinate of the window relative to a user’s monitor screen
screenXspecifies the x coordinate for the window relative to a user’s monitor screen
screenYSpecifies 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:

Window object properties in JavaScript

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

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading