spacer

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

home / experts / javascript / column7


Manipulating a New Window

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

As you know from the previous section, you can refer to the new window's window object after launching it. Thus, any method of the window object can be invoked to manipulate the new window. The most important method is obviously the one that closes the window: window.close(). So if you assign the new window to a variable named myRemote, you would have to invoke myRemote.close() to close the window:

myRemote.close();

You can also load a new document in the remote window, by assigning an URL to the location.href property. Here's an example:

myRemote.location.href = "http://www.webreference.com/";

But what happens if the user closed the new window? The browser would generate an error, because the object no longer exists. Therefore, you should check if the remote window still exists. The following statement closes the remote window if it still exists:

if (window.myRemote) myRemote.close();

If you're using a method that isn't supported by all JavaScript-enabled browsers, you should check if the new window exists, and then if the method exists. There are two ways to do this. The first one relies on short-circuit evaluation, whereas the second one doesn't. Take a look at the following example (using both methods):

if (window.myRemote && myRemote.moveTo)
  myRemote.moveTo(0, 0);

if (window.myRemote && window.moveTo)
  myRemote.moveTo(0, 0);

http://www.internet.com

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

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