DOM API - The "window.open" Method

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 built-in object "window" also allows you to create a new browser window and returns a new window object. You can manipulate the new browser window through this object.

Here is JavaScript tutorial example that uses the window.open() method to create a new window:

<html>
<!-- Window_Object.html
   Copyright (c) 2008 HerongYang.com. All Rights Reserved.
-->
<head>
<title>Window Object</title>
<script type="text/javascript">
var mySize = 0;
var myWin;

function openWin() {
   myWin = window.open('','','left=300,top=100,width=600,height=600');
   myWin.focus();
}

function changeSize() {
   if (mySize == 0 )
      myWin.resizeTo(300,300); 
   else if (mySize == 1 )
      myWin.resizeTo(400,400); 
   else if (mySize == 2 )
      myWin.resizeTo(500,500); 
   else if (mySize == 3 )
      myWin.resizeTo(600,600); 
   mySize = (mySize+1)%4;
   myWin.focus();
}

function closeWin() {
   myWin.close();
}

</script>
</head>
<body>
<p>Click "Create Window" first start the test:</p>
<p><form>
  <input type="button" value="Create Window" onClick="openWin();"/>
  <input type="button" value="Resize Window" onClick="changeSize();"/>
  <input type="button" value="Close Window" onClick="closeWin();"/>
</form></p>
</body>
</html>

Run this JavaScript example in a Web browser and follow these steps to test this tutorial:

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

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

 type="text/javascript" or language="JavaScript"

 JavaScript Version Supported by Browsers

 Including 'script' Tags in String Literals

 Escaping 'script' Tags in String Literals

 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

 JavaScript Console in Google Chrome

 JavaScript Console in Mozilla Firefox

 JavaScript Console in Apple Safari

 JavaScript Console in IE (Internet Explorer)

 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

 AJAX (Asynchronous JavaScript And XML)

 References

 Full Version in PDF/EPUB