Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The JavaScript FAQ
Prev Home Next

Opening a window

Question: How do I open a new browser window?

Answer: To open a new browser window, use the window.open() method. For example, the following code opens this page in a new window.

myRef = window.open(''+self.location,'mywin',
'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');

The general syntax of the window.open() method is as follows:

winRef = window.open( URL, name [ , features [, replace ] ] )
The return value, stored in the variable winRef, is the reference to your new window. You can use this reference later, for example, to close this window (winRef.close()), give focus to the window (winRef.focus()) or perform other window manipulations.

The parameters URL, name, features, replace have the following meaning:
URL String specifying the location of the Web page to be displayed in the new window. If you do not want to specify the location, pass an empty string as the URL (this may be the case when you are going to write some script-generated content to your new window).
name String specifying the name of the new window. This name can be used in the same constructions as the frame name provided in the frame tag within a frameset <FRAME NAME=name ...>. For example, you can use hyperlinks of the form <a target=name href="page.htm">, and the hyperlink destination page will be displayed in your new window.

If a window with this name already exists, then window.open() will display the new content in that existing window, rather than creating a new one.

features An optional string parameter specifying the features of the new window. The features string may contain one or more feature=value pairs separated by commas.
replace An optional boolean parameter. If true, the new location will replace the current page in the browser's navigation history. Note that some browsers will simply ignore this parameter.

The following features are available in most browsers:
toolbar=0|1 Specifies whether to display the toolbar in the new window.
location=0|1 Specifies whether to display the address line in the new window.
directories=0|1 Specifies whether to display the Netscape directory buttons.
status=0|1 Specifies whether to display the browser status bar.
menubar=0|1 Specifies whether to display the browser menu bar.
scrollbars=0|1 Specifies whether the new window should have scrollbars.
resizable=0|1 Specifies whether the new window is resizable.
width=pixels Specifies the width of the new window.
height=pixels Specifies the height of the new window.
top=pixels Specifies the Y coordinate of the top left corner of the new window. (Not supported in version 3 browsers.)
left=pixels Specifies the X coordinate of the top left corner of the new window. (Not supported in version 3 browsers.)

JavaScripter.net. Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next


 
 
  Mirrored with kind permission of Alexei Kourbatov Design by Interspire