January 06, 2003

Revisiting the scriptable DOM

We can work across browsers and operating systems

The scriptable DOM (Document Object Model) was always an intoxicating idea. Mobile scripts that lived in Web pages -- and could inspect and modify their hosts -- seemed rich with possibility. But when I saw the gymnastics those poor scripts had to perform in order to detect and adapt to browser versions, I recoiled in horror. There was no way I was going to use, or recommend, such a fragmented technology.

Recently, though, my LibraryLookup project[1] has reacquainted me with the world of JavaScript and the DOM. I was pleasantly surprised to find that scripts I wrote in Mozilla, under Mac OS X, worked identically under MSIE 6 on Windows. This is great news! It means that we're now in a position to reap the benefits of a class of software I'll call "interactive service intermediaries."

Here's the example I came up with. Suppose your LibraryLookup bookmarklet reveals that your local library doesn't carry a book you're interested in. Many OPACs (online public access catalogs), including the one my library uses, enable you to request acquisition of the book. Filling out the form is a chore, though, so I wondered if I could use JavaScript to automate it.

The recipe for doing that involved three crucial ingredients. First, Amazon.com's pages consistently store title and author information in the first META tag, like so:

<META name="description" content="Guns, Germs, and Steel: The Fates of Human Societies, Jared Diamond">

Second, the browser's now-standard DOM makes that metadata easily accessible, like so:

var m0 = document.getElementsByTagName('META')[0]; var titleAuthor = m0.getAttribute('content');

In other words, get the object corresponding to the first metatag in the document, and then get the value of its "content" attribute.

Third, JavaScript's Perl-style regular expressions make quick work of capturing semistructured data -- in this case, separating the elements of the comma-delimited title/author value:

var re = /(.+),\s*([^,]+)$/; // define the regular expression

re.test(titleAuthor); // apply it

var title = RegExp.$1; // get everything before the last comma

var author = RegExp.$2; // get everything after the last comma

There's nothing new here, of course, but it's exciting to discover that it is finally possible to deploy such code with a high probability that it will work across browsers and operating systems.

Packaged as a bookmarklet, the script I wrote functions as an intermediary between Amazon and my library's OPAC. When I'm on an Amazon book page and I'd like to ask my library to acquire that book, I click the bookmarklet. It intermediates between Amazon, which from this perspective is an informational service, and the library, which can receive what is in effect a purchase order. The intermediation is interactive in the sense that the script does not directly transmit the purchase order, but rather presents it to me -- as a generated form -- for my approval.

Of course neither Amazon nor the library's OPAC is a formal XML Web service. But this principle of interactive intermediation will apply equally in that case. We think of Web services as a kind of application-to-application communication, and indeed they are, but we'll often want to involve people too. The scriptable DOM is turning out to be a great way to bring people into the loop.

1. http://weblog.infoworld.com/udell/stories/2002/12/11/librarylookup.html

Close

On Twitter now

Applications

Powered by Twitter

On Twitter now

White Paper

D2D Virtual Tape Library Replication Primer

This whitepaper explains the terminology and concepts behind Data Replication technologies and establishes some sizing rules through worked examples. Learn the new paradigm in disaster tolerance—protect data anywhere.

Download now »

White Paper

An Alternative to Virtualization for Datacenter Cost Savings

Server virtualization is a popular option for dealing with mounting datacenter costs. Another equally promising approach is the use of an Application Delivery Controller. Citrix NetScaler provides a low-cost way for organizations to reduce their server count and accrue cost savings from a reduction in space, cooling, power and personnel.

Download now »

White Paper

Why Your Firewall, VPN, and IEEE 802.11i Aren't Enough to Protect Your Network

The emergence of WLANs has created a new breed of security threats to enterprise networks.

Included in HP ProCurve WLAN solutions is security technology that alleviates threats from WLANs through:
* Monitoring wireless activity inside and out of the enterprise
* Classifying WLAN transmissions into harmful and harmless
* Preventing transmissions that pose a security threat to the enterprise network
* Locating participating devices for physical remediation

Download now »

White Paper

Bringing the Edge to the Data Center

Effectively address data protection challenges, implementing solutions that help store and protect business–critical data while cutting costs and improving efficiency and reliability.

Download now »

Sign up to receive Applications Resource Alerts

Subscribe to the Applications Newsletter

Stay informed of the latest news and technologies around application, project and performance management.

White paper

Turn Your IT Department into a Lean Machine

Like any valuable resource, IT is a terrible thing to waste. But by applying the same lean techniques that have been used to streamline manufacturing processes, IT departments can reduce costs, improve performance and better manage resources.

Download now! »

Podcast

Economy Makes Automation a Must-Have Tech for 2009

Stephen Elliot, vice president of strategy for CA's Infrastructure Management and Data Center Automation business unit, explains why difficult economic times drive the need for simplified management capabilities and advanced automation tools.

Listen now! »

White paper

What You Need to Know About Virtual Infrastructure Management - Now

According to a recent study CA conducted with 300 CIOs and top IT executives, 64 percent of respondents say they've already invested in virtualization, and the other 36 percent reported that they plan to invest in virtualization.

Download now! »

Webcast

Leveraging Virtualization and Process Automation

In this video learn about process automation in a virtualized world. How CA and VMware are enabling enterprise datacenter automation.

View now! »
©1994-2009 Infoworld, Inc.