The Capabilities of Scripting

Scripting offers great features as well as some inherent limitations. On the upside, scripts (in their simple form) are easy to learn and use, they run on the client side, they can be developed quickly, and they are powerful. On the downside, scripts have some security-based limits, are not as fast as traditional compiled languages (like C++) for computationally intense operations, and they can sometimes be complex.

EASE OF USE Basic scripting is extremely easy to learn and use. Scripts bring much of the power of programming to the nonprogrammer in the form of simple blocks of code that respond to user actions (event-driven code). For instance, it is easy to make a simple chunk of code run when the user clicks a specific image. With scripting languages, you can also avoid many of the more time-consuming and difficult tasks in traditional programming, such as memory management and garbage collection. In addition, you don't need special tools or a development environment to get started with scripts. The advantages of scripting are available to anyone who has a browser and a simple text editor.

CLIENT-SIDE PROCESSING Another significant advantage is that scripts run on the client side. Once a page has been downloaded, all its scripts run on the user's browser rather than on a server that might be halfway around the world. (This advantage is especially important when combined with other features such as form validation, multimedia, and the Dynamic HTML Object Model, as you will see later.) This is quite different from the old method of sending the user a new Web page every time the page should change content or appearance. Anyone who views your Web pages with a script-capable browser can use your scripts without installing any extra software—and potentially without even knowing that scripts are being used. To the viewer, scripts are seamless and invisible.

RAPID DEVELOPMENT Scripts are interpreted languages—that is, it is not necessary to compile the code before it is run, as it is for C++ and other traditional programming languages. As a developer, you can create a script in an HTML file and execute it immediately in a browser. If you need to make a change to the script, you can simply edit the HTML file, reload it in the browser, and instantly view the effect of your change.

POWER Despite their simplicity, scripts can be very powerful. While novices enjoy the ease of learning, advanced programmers like the power, flexibility, and advanced features of scripts. These features include object orientation, the ability to create objects at run time, support for a variety of data types, and control over virtually everything in the browser. Scripts allow Web page creators to add sophisticated logic to their pages, making the pages both active and interactive.

SECURITY ISSUES The power of scripting in the browser is limited in certain areas. Other than certain very specific cases (for example, cookies, Default Behaviors, and the FileSystem ActiveX control), Internet Explorer does not allow scripts to read or write files on the user's hard disk. This prohibition is intended to prevent rogue Web programmers from damaging end users' hard disks or stealing their data. For those developing tools that require more extensive hard drive access, the Windows Scripting Host allows you to write script for Windows outside a browser, and the FileSystem ActiveX control (which must be specifically loaded and approved by the user) allows you to write script for the file system and hard drive from within Web pages.

PERFORMANCE Because VBScript and JScript were designed for ease of use and simplicity, they do not offer the same level of performance that many traditional compiled languages offer. For example, it is possible to write a mathematically intensive encryption program in JScript, but it would probably be prohibitively slow. However, this is not normally much of a restriction because most tasks you would want to perform in a browser do not require high computational performance.

COMPLEXITY A common misconception is that because basic scripting is easy, all scripting is easy. In fact, VBScript and JScript are sophisticated languages, and mastering them requires a thorough understanding of programming concepts. Because of this complexity, beginners are often a bit overwhelmed when first exposed to advanced scripts. Fortunately, many users will never need advanced scripting techniques because so much is possible with simple event-driven code.

Overall, you will find that scripts are invaluable resources in creating sophisticated, interactive Web pages that take full advantage of the power of the browser. Let's take a look at how scripts work.



Dynamic HTML in Action
Dynamic HTML in Action
ISBN: 0735605637
EAN: 2147483647
Year: 1999
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net