O'Reilly logo

Prototype and Scriptaculous: Taking the Pain out of JavaScript by Chris Angus

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Using Prototype

The Prototype distribution is available from http://prototype.conio.net. The file prototype-x.x.x.js (at the time of writing: prototype-1.4.0.js) should be saved to a convenient location and renamed prototype.js.

Figure 3-1. Prototype download page

Using Prototype involves making the script in prototype.js visible to your own JavaScript. This is usually done via the script tag specifying the URL of prototype.js:

<script src="URL" content="text/javascript"></script>

Although Prototype can be referenced directly from the prototype distribution site, it is preferable and faster to work locally.

The following example assumes that prototype.js has been placed in a js directory and that the HTML file is alongside that directory.

C:\javascriptBook>dir /s /b
C:\javascriptBook\js
C:\javascriptBook\referencingPrototype.html
C:\javascriptBook\js\prototype.js

The example shows a sample HTML file that uses Prototype and may be used as a simple sanity check.

Example 3-1. referencingPrototype.html
<html>
<head>
    <title>Using Prototype</title>
    <script src="js/prototype.js" content="text/javascript"></script>
</head>
    <body id='body'>
    <script content="text/javascript">
    new Insertion.Top($('body'),'Using Prototype version:'+Prototype.Version);
    </script>
</body>
</html>

If you are using a JavaScript as your only scripting language, you may alternatively set this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required