spacer

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

home / programming / javascript / diaries / 8

[previous] [next]

Senior Consultant/Information Security - permanent position (TX)
Next Step Systems
US-TX-Irving

Justtechjobs.com Post A Job | Post A Resume
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

The JavaScript Diaries: Part 8

By 

open()

This method is used for opening a new window. It takes three parameters: the URL of the file to be opened, the name of the window (for reference) and the attributes to be used in the new window. (The attributes are also known as "browser chrome." These make up the elements of the browser, i.e. scrollbars, toolbars.) The format is:

window.open("URL", "window name", "attributes");

If you do not give the URL of a file, you still need to list the double quotes, "", which will open a blank window. This is useful if you are creating the content of the new window from your script. The second parameter can also be left blank but the double quotes must stated, ( "" ). To open a new window using the same attributes as the current window, you can just leave the attributes portion out, e.g.:

window.open("URL", "window name");

If you use any of the attributes, even if it's only one, the rest are defaulted to "no." Using the name of the attribute when it has a Boolean value sets the value of the attribute to true. If it's not used, its Boolean value is set to false. A list of the most common attributes is displayed below.

AttributesDescription
widthSets the width of the new window in pixels
heightSets the height of the new window in pixels
leftDistance of new window from top left corner of current window in pixels
topDistance of new window from top of current window in pixels
menubarDetermines whether menubar is displayed (yes/no)
toolbarDetermines whether toolbar is displayed (yes/no)
locationDetermines whether the location bar is displayed (yes/no)
scrollbarsDetermines whether scrollbars are displayed, if necessary (yes/no)
statusDetermines whether status bar is displayed (yes/no)
resizableDetermines whether new window can be resized (yes/no)
directoriesDetermines whether directory buttons are displayed (yes/no)

You can try different combination of these attributes and see what they produce. Try the examples below, placing them in the <head> portion of the document. If you use them in an actual script, placing them in an external file is preferable. (In the examples below I have not given a URL of an existing file or the name of the window. Doing it this way will just open a new, blank window.) The scripts can all be accessed by placing the following code within the <body> section:

<form>
<input type="button" name="win" value="Open window" onclick="popNewWin()"><br>
</form>

This function sets the width, height and top and specifies the display of the status bar. (Be sure not to leave any spaces between the commas in the attributes portion as it can cause display problems in some browsers.)

function popNewWin() {
  var newWin;
  newWin=window.open("", "", "status,width=200,height=200,top=300,left=300");
}

This function sets the width and height and specifies the display of the location bar and menubar.

function popNewWin() {
  var newWin;
  newWin=window.open("", "", "width=200,height=200,location,menubar");
}

This function specifies the display of the toolbar, menubar and allows the window to be resized.

function popNewWin() {
  var newWin;
  newWin=window.open("", "", "toolbar,menubar,resizable");
}

This function does not set any attributes. That means it will open with the same attributes of the window that opened it.

function popNewWin() {
  var newWin;
  newWin=window.open("", "");
}

Let's put this new skill to work and see how it operates.

home / programming / javascript / diaries / 8

[previous] [next]

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

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle

Created: August 19, 2005

URL: