spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column7


Launching a Window with JavaScript

Developer News
ActiveState Debuts Open Source Business Suite
Salesforce Offers Visual App Builder
Codesion Steps Out From CVS's Shadow

The window.open() method opens a new browser window. Its general syntax is:

window.open(windowURL, windowName, windowFeatures);

In a standard script (not an event handler) the window specification is not necessary:

open(windowURL, windowName, windowFeatures);

windowURL is a string specifying the URL to open in the new window. If you specify an empty string, the method opens an empty window with no initial document.

windowName is a string specifying the window name to use in a TARGET attribute to load a page or a form response.

windowFeatures is a string containing a comma-separated list determining whether or not to create various standard window features. These options are described in the next section of the column.

A new browser window is almost useless if you cannot reference it in the original window's scripts. Since the method returns a reference to the new window, you should normally assign it to a variable:

var remote = open(windowURL, windowName, windowFeatures);

It's also very convenient to assign a name to the original window, so you can use the TARGET attribute in the new window to target the original one. The following function opens a new window, names the original window, and returns a reference to the new window's window object:

function launch(newURL, newName, newFeatures, orgName) {
  var remote = open(newURL, newName, newFeatures);
  if (remote.opener == null) // if something went wrong
    remote.opener = window;
  remote.opener.name = orgName;
  return remote;
}

Note that the window object of any new window created with the window.open() method, features an opener property, which reflects the window object of the opener window.

Back to the function. You should invoke this function like the window.open() function, with the addition of a single argument: the name of the opener window. In the next section of the column, we'll show you exactly how to use this function.

http://www.internet.com


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Use Web Caching to Make Your Web Site Faster · Creating an Online Shopping Cart Mechanism in PHP · Log JavaScript Errors Using an AJAX-driven Web Service
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Configuring Granular Settings for a Database Level Audit · The Perils of a Web 2.0 Transition on Your Business Processes · Facebook Redesigns Site —Again — Nears 400M Mark

Created: November 18, 1997
Revised: December 4, 1997
URL: http://www.webreference.com/js/column7/jslaunch.html