spacer

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

home / programming / javascript / diaries / 8

[next]

Web Project Manager
Aquent
US-PA-Collegeville

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

  1. Introduction
  2. Data Types & Variables
  3. Operators
  4. Functions
  5. Conditional Statements and Loops
  6. Objects
  7. Browser-Based Objects
  8. Window Methods
  9. Window Event Handlers
  10. Navigator, Screen, History and Location Objects
  11. Arrays: Part 1 - Introduction
  12. Arrays: Part 2 - Multiple Array Types
  13. Arrays: Part 3 - Array Properties and Methods
  14. The Math Object
  15. The Date Object

By 

In this installment we are going to take a look at the methods that are associated with the window object. Here we will look at what they are and how they work. Later on in this series we will work with them in greater detail. Until now, we've been learning how to build the framework of our scripts but now we'll start to see things happen! Using these methods you'll learn how to implement JavaScript in your Web sites.

Methods

To review, a method does something to the object or with the object. (Think of it as a "method" of accomplishing a specific task.) It's a command given to the object. A method can cause a new browser window to open, or it can cause text to be selected. According to the Core JavaScript Guide 1.5: "A method is a function associated with an object. You define a method the same way you define a standard function." Just like a function, a method also ends with a set of parentheses. If parameters are given to the method, just like the function, they will go inside the parentheses, but unlike a function, a method can act on a window object.

(You can download a zipped copy of the Core JavaScript Guide 1.5, written by Netscape developers. The Core JavaScript 1.5 Reference Manual can be viewed online or also downloaded in zip format.)

alert()

This method issues a command to open a popup window that displays a message to the visitor. We have already used this method in some of our previous sessions. The format is:

window.alert("How are you doing?");

The line of code tells the JavaScript interpreter to open a window within the current window environment displaying the text, "How are you doing?" Since the window object is the highest level object, making it the default object, it's permissible to drop the window portion and just use the method by itself. Also, in the case of the alert(), prompt(), and confirm() methods, they are not relative to any other window. The typical style of writing it would be:

alert("How are you doing?");

The format of the alert window itself, including the "OK" button, cannot be changed. You only have access to the message inside the window.

prompt()

This method issues a command to open a popup window that displays a prompt for the visitor to enter information. We have already used this method in some of our previous sessions. The format is:

window.prompt("Please provide your name","optional text");

The line of code tells the JavaScript interpreter to open a window within the current window environment and prompt the user to input data. The window will display the message text, "Please provide your name." The second parameter is optional and is used to suggest an entry in the input box. It will display the text in the input box of the window. Once again, since the window object is the highest level object, it's permissible to drop the window portion and just use the method by itself. The typical style of writing it would be:

prompt("Please provide your name","optional text");

Like the alert window, the format of the prompt window, including the "OK" and "Cancel" button, cannot be changed.

confirm()

This method issues a command to open a confirmation window for the visitor. We have already used this method in some of our previous sessions. The format is:

window.confirm("Are you sure you want to do this?");

As I said before, since the window object is the highest level object, it's permissible to drop the window portion and just use the method by itself. The typical style of writing it would be:

confirm("Are you sure you want to do this?");

As with the alert and prompt windows, the format of the confirmation window, including the "OK" and "Cancel" button, cannot be changed.

home / programming / javascript / diaries / 8

[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
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
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: