Javascript Library

Scripts

This is a collection of scripts that I've created and/or modified. All the scripts are released under a Creative Commons License. Do whatever you want with them - use them as is or modify them to suit your purposes. Both personal and commercial usage is ok by me.

Unless otherwise noted, all scripts degrade gracefully in older browsers that don't support the functionality the script provides (ie. no error messages are triggered) and, with the obvious exception of the Browser Detect script, all use object detection instead of browser detection (which ensures a broad range of browsers will run these scripts including future browsers).

I considered including browser support information in the documentation for each script. But a list of supported browsers would be difficult to compile and maintain. Instead, I have included the version of the script engine (the Javascript or JScript version) needed to run the script. For script that require a particular Document Object Model, I've included that too. I've used a programming syntax for this information and, for scripts that support a couple script engines and proprietary DOMS or architectures, this can result in something as complex as:

( Javascript 1.1 | ( JScript 2.0 & VBScript 2.0 ) | ECMAScript 1.0 ) & ( Netscape plugin architecture | MSIE ActiveX architecture )

Which translates as requiring either Javascript 1.1 or the combination of JScript 2.0 and VBScript 2.0 or ECMAScript 1.0 as the script engine and either the Netscape plugin architecture or the Microsoft ActiveX architecture. This includes browsers like NS3 and up, IE3 and up on Windows, IE5 and up on the Mac, Safari, Opera3+, and others. If this is all very confusing for you, don't worry: all the scripts have been written to support the widest possible browser audience and errors will not occur in unsupported browsers.

As of 06/11/2001, all scripts have version numbers.

Scripts for Specific Functionalities

1k DHTML API

A simple, low-level DHTML API that weighs in at 1065 bytes. You can also download lighter variants and libraries built for the API.

Acrobat (PDF) Detection / Redirection

A collection of scripts that perform in-page Adobe Acrobat Reader detection or redirection. Detection of all Acrobat versions up to 5 on IE5+ on the Mac, Netscape 3+, and Opera 3+ and versions 4 to 5 in IE4+ on Windows.

Browser Detect

A script that can identify a visitor's browser. Supports IE, Netscape, Mozilla and other Gecko-based browsers, Safari and other KHTML-based browsers, Opera, iCab, and AOL. Also determines the visitor's platform: Windows, Mac, Unix, or Linux. And level of Javascript and DOM support.

Cookie API

The standard set of functions to read and write cookies.

Countdown Timer

A countdown timer that tracks the number of days, hours, minutes, seconds, and milliseconds (if you want) until a date and time that you set. Changes in real time. Image or text-based.

Flash Detection / Redirection

A collection of scripts that perform in-page flash detection or redirection. Detection of Flash versions 3 to 7 (with future support for version 8 built-in) in IE4+ on Windows, IE5+ on the Mac, Netscape 3+, Opera 3+, and WebTV2.5+.

Form Functions

A loose grouping of functions that work with forms.

Form Validation

Functions that perform common validations on form values (or any other values). These include credit card, email, and alphanumeric checks.

Image Preloader

Load images into a visiting browser's cache to speed the display of future pages.

Quicktime Detection / Redirection

A collection of scripts that perform in-page quicktime detection or redirection. Detection of both the Quicktime plugin and the ActiveX control (version 4.1.1+) in IE4+ on the Windows, IE5+ on the Mac, Netscape 3+, and Opera 3+.

Rollovers

Image rollovers with minimal (bordering on no) installation. Ease of use does limit the cross-browser-ness of the script (only browsers that support event handlers on <img> tags are supported so rollovers won't work in NS4.x).

Window Opener Functions

A set of functions that simplify creating windows and popups.

Window Properties

Cross-browser querying of window dimensions and scroll position.

DOM Support / Extensions

One thing that always bothered me about most DHTML APIs is that they introduce a whole set of non-standard properties and methods in order to deal with the fact that not all browsers implement the standard properties and methods. It would be better to attempt to preserve a standard. For instance, in order to get a reference to an element, the standard defines document.getElementById(). For systems that don't support this method, one could create a method of the document object with the name getElementById that mimics the standard behaviour. In this way, when all your target browsers support the standard to perform a task, you aren't still using a non-standard method to perform the same task.

These scripts grew out of this belief. Whenever I came across DOM functionality that was absent from or implemented differently in IE5+, I tried to write a script to build that functionality or map the existing functionality onto the DOM. I've broken them into individual scripts based on the related W3C modules.

Array Extensions

Extends the standard Array object in any Javascript 1.1 and above browser by adding the methods defined in Javascript 1.2 (including those missing from IE5.0 Windows and IE5.x Mac). Allows for more flexible manipulation of arrays in cross-browser applications. Though the Array object is defined in the Javascript Core and isn't part of the DOM, this script shares the same philosophy as the DOM scripts so I've grouped it with them.

DOM1 Core

Currently just defines the nodeType constants missing from IE5+.

DOM2 Events

A synthetic event object that follows the DOM2 Event standard and corrects browser quirks in such properties as timeStamp, button, clientX, and clientY. A number of non-standard but helpful properties like pageX, pageY, and keyCode.

DOM2 Traversal

Provides an implementation of NodeFilter and TreeWalker interfaces for IE5+.

DOM2 Views

document.defaultView and getComputedStyle().

DOM Extensions

Stuff not part of the DOM standard but very helpful. Currently just contains functions that provide consistent values for offsetTop and offsetLeft properties in IE and Mozilla.

Tools

Javascript Compression

A set of Javascript-based compression tools for compressing Javascript code and for full HTML pages. Used to compress the variants and subsets of the 1k DHTML API. Perfect for 5k contest entries. Also based on a 5k entry.

Recent Updates

Apr 15, 2004

Browser Detect

Changed isFirebird variable to isFirefox.

Apr 7, 2004

Form Validation

Better radio group validation and fixed example page for same.

Licensing

These scripts are released under a Creative Commons License.