JavaScript Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 2.11

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 changing browser window size through the 'window' object.

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

  • The "window" object is a browser built-in object that represents the browser window that contains the current HTML document.
  • The "window" object offers a number of properties and methods to allow you
  • The "document" object and its "node" objects offers various methods to allow you to manipulate the window.

To illustrate some nice features of the "document" object, I wrote this JavaScript tutorial example:

<html>
<!-- Window_Object.html
   Copyright (c) 2008 by Dr. Herong Yang, http://www.herongyang.com/
-->
<head>
<title>Window Object</title>
<script type="text/javascript">
var sizeID = 0;
function changeSize() {
   if (sizeID == 0 )
      window.resizeTo(300,300); 
   else if (sizeID == 1 )
      window.resizeTo(400,400); 
   else if (sizeID == 2 )
      window.resizeTo(500,500); 
   else if (sizeID == 3 )
      window.resizeTo(600,600); 
   sizeID = (sizeID+1)%4;
}
</script>
</head>
<body>
<p>Hello World!</p>
<p><form>
  <input type="button" value="Change" onClick="changeSize();"/>
</form></p>
</body>
</html>

Run this JavaScript example in a Web browser, and click the "Change" button. The browser window will change its size each time you click the button.

For more tutorial examples on the "window" object, see the DOM API chapters in this book.

Sections in This Chapter

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

Event Listeners and Objects

'javascript:' Pseudo-URL Addresses

Dr. Herong Yang, updated in 2008
DOM API - The "window" Object