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: 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. https://weblog.infoworld.com/udell/stories/2002/12/11/librarylookup.html Software Development