| About InfoWorld : Advertise : Subscribe : Contact Us : Awards : Events : Store |
|
||||
|
||||
Revisiting the scriptable DOM 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.
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 Jon Udell is lead analyst at the InfoWorld Test Center. Contact him at jon_udell@infoworld.com and check out his Weblog at http://weblog.infoworld.com/udell. RELATED SUBJECTS SPONSORED WHITE PAPERS
SPONSORED LINKS
|
|||||||||||||||||||||||||||||||||||||||
|
||||||||||