DOM API - The "window" Object

This section provides a quick description of the 'window' object of the DOM API. A tutorial example is provided on retrieving properties from the current browser window.

The DOM API provided by the Web browser contains another useful object called "window", which has the following features:

To illustrate how to retrieve properties from the current window, I wrote this JavaScript tutorial example:

<html>
<!-- Window_Properties.html
   Copyright (c) 2013 by Dr. Herong Yang, herongyang.com
-->
<head>
<title>Window Properties</title>
<script type="text/javascript">
function getWindowProperties() {
   var text = "";
   text += "'document' property: "+ window.document.title+"\n";
   text += "'location' property: "+ window.location.pathname+"\n";
   text += "'history' property: "+ window.history.length+"\n";
   text += "'navigator' property: "+ window.navigator.appCodeName+"\n";
   text += "'outerWidth,outerHeight' property: "
      + window.outerWidth+","+ window.outerHeight+"\n";
   text += "'innerWidth,innerHeight' property: "
      + window.innerWidth+","+ window.innerHeight+"\n";
   text += "'screenX,screenY' property: "
      + window.screenX+","+ window.screenY+"\n";
   return text;
}
</script>
</head>
<body>
<pre>
<script type="text/javascript">
   document.write(getWindowProperties());
</script>
</pre>
</body>
</html>

Run this JavaScript example in Firefox browser, you will get something like this:

'document' property: Window Properties
'location' property: /C:/herong/Window_Properties.html
'history' property: 3
'navigator' property: Mozilla
'outerWidth,outerHeight' property: 1024,608
'innerWidth,innerHeight' property: 1006,485
'screenX,screenY' property: 72,73

This tutorial shows that:

See the next tutorial on how to create a new Window with the window.open() method.

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

Web Browser Supporting JavaScript

 JavaScript Support in Web Browsers

 Including JavaScript Codes with HTML "script" Tags

 Including 'script' Tags in String Literials

 Escaping 'script' Tags in String Literials

 Using HTML Entities to Protect HTML Tags

 Including JavaScript Codes as External Files

 DOM API - The "document" Object

DOM API - The "window" Object

 DOM API - The "window.open" Method

 Event Listeners and Objects

 'javascript:' Pseudo-URL Addresses

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

 'jrunscript' - JavaScript Shell Command from JDK

 Using Functions as "Function" Objects

 Introduction to Built-in Object Types

 W3C's Document Object Model (DOM) Specifications

 References

 PDF Printing Version