spacer

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

home / programming / javascript / diaries / 8

[next]

JAVA Developer – Trading Industry (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
ActiveState Debuts Open Source Business Suite
Salesforce Offers Visual App Builder
Codesion Steps Out From CVS's Shadow


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]


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: August 19, 2005

URL: