Tuesday, May 20, 2008

JavaScript: The Right Tool for the Right Job

Knowing how to match an authoring tool to a solution-building task is an important part of being a well-rounded Web page author. A Web page designer who ignores JavaScript is akin to a plumber who bruises his knuckles by using pliers instead of the wrench at the bottom of the toolbox.

By the same token, JavaScript won’t fulfill every dream. The more you understand about JavaScript’s intentions and limitations, the more likely you will be to turn to it immediately when it is the proper tool. In particular, look to JavaScript for the following kinds of solutions:

Getting your Web page to respond or react directly to user interaction with form elements (input fields, text areas, buttons, radio buttons, checkboxes, selection lists) and hypertext links—a class of application I call the serverless CGI

Distributing small collections of database-like information and providing a friendly interface to that data

Controlling multiple-frame navigation, plug-ins, or Java applets based on user choices in the HTML document

Preprocessing data on the client before submission to a server

Changing content and styles in modern browsers dynamically and instantly in response to user interaction

At the same time, understanding what JavaScript is not capable of doing is vital. Scripters waste many hours looking for ways of carrying out tasks for which JavaScript was not designed. Most of the limitations are designed to protect visitors from invasions of privacy or unauthorized access to their desktop computers.

Therefore, unless a visitor uses a modern browser and explicitly gives you permission to access protected parts of his or her computer, JavaScript cannot surreptitiously perform any of the following actions:

Setting or retrieving the browser’s preferences settings, main window appearance features, action buttons, and printing

Launching an application on the client computer

Reading or writing files or directories on the client or server computer

Capturing live data streams from the server for retransmission

Sending secret e-mails from Web site visitors to you

Web site authors are constantly seeking tools that will make their sites engaging (if not “cool”) with the least amount of effort. This is particularly true when the task is in the hands of people more comfortable with writing, graphic design, and page layout than with hard-core programming. Not every Webmaster has legions of experienced programmers on hand to whip up some special, custom enhancement for the site. Nor does every Web author have control over the Web server that physically

houses the collection of HTML and graphics files. JavaScript brings programming power within reach of anyone familiar with HTML, even when the server is a black box at the other end of a telephone line.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home