<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Depth-First: Tag objecttag</title>
    <link>http://depth-first.com/articles/tag/objecttag</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Walking the Web of Chemical Informatics</description>
    <item>
      <title>Building WebSpex: Putting Custom Data Types In Their Place</title>
      <description>&lt;p&gt;&lt;a href="http://flickr.com/photos/mdezemery/457694256/"&gt;&lt;img src="http://depth-first.com/demo/20080724/spectrum.jpg" align="right"&gt;&lt;/img&gt;&lt;/a&gt;The previous article in this series introduced &lt;a href="http://depth-first.com/articles/2008/07/17/javascript-for-cheminformatics-an-introduction-to-webspex-a-spectroscopy-tool-for-the-internet"&gt;WebSpex&lt;/a&gt;, a spectroscopic data visualization tool being designed especially for use in a Web browser. Previously, the platform on which the user interface would be built was discussed. This article will discuss the question of where to put the spectroscopy data that WebSpex will display.&lt;/p&gt;

&lt;h4&gt;Tag Soup&lt;/h4&gt;

&lt;p&gt;We've decided to target WebSpex for use on the Web, which means that spectroscopy data would need to be referenced or embedded in a Web page. How should we do this? The answer, it turns out, is far from obvious.&lt;/p&gt;

&lt;p&gt;If we knew that WebSpex were going to be created as a Java or Flash applet, which is not the current plan, we might be tempted to pass a reference to the data (or the data itself) as a parameter in the &lt;a href="http://depth-first.com/articles/2008/03/12/demystifying-java-applets-part-3-failing-gracefully-when-your-users-dont-have-java"&gt;&lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; tag&lt;/a&gt;. For an applet, this might look something like:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;object&lt;/span&gt; &lt;span class="attribute"&gt;type&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;application/x-java-applet;version=1.4.2&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;width&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;520&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;height&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;350&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;code&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;com/metamolecular/webspex/applet/FullApplet.class&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;archive&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;http://metamolecular.com/applets/webspex.jar&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;jcamp&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;http://base-url/spectrum.jdx&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In the example above, the parameter &lt;tt&gt;jcamp&lt;/tt&gt; would encode the path to a JCAMP-DX file for WebSpex to load.&lt;/p&gt;

&lt;p&gt;Alternatively, if we were going to develop WebSpex as a Flash applet, we might use an object tag like this:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;object&lt;/span&gt; &lt;span class="attribute"&gt;type&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;application/x-shockwave-flash&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;width&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;520&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;height&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;350&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;movie&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;webspex.swf&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;FlashVars&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;filename=http://spectrum.jdx&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In this example, we associate the parameter &lt;tt&gt;filename&lt;/tt&gt; with the value "spectrum.dx" using &lt;a href="http://www.permadi.com/tutorial/flashVars/index.html"&gt;FlashVars&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This works well enough, but what if we need to load a custom data type in a Web page without a plugin?&lt;/p&gt;

&lt;h4&gt;Some Options&lt;/h4&gt;

&lt;p&gt;There are a few options for including custom data in an HTML document:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Invent our Own Tag&lt;/strong&gt; Browsers are designed to ignore content they don't understand. We could just hack our own tag, let's call it &lt;tt&gt;&amp;lt;spectrum&amp;gt;&lt;/tt&gt;. But for a variety of reasons, this is a bad idea. Most importantly, we'd be breaking with conventions used worldwide, which is never a good idea without a very good reason. For another, any developer tools we'd use would probably complain about a mis-formed HTML document. Still another reason might be that browsers could parse our invented tag in unpredictable ways. We may also run into problems with search engines not indexing our content properly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use XHML&lt;/strong&gt; We could try inventing a tag the right way: with &lt;a href="http://en.wikipedia.org/wiki/XHTML"&gt;XHTML&lt;/a&gt;. This might be a worthwhile option if our data type (&lt;a href="http://dx.doi.org/10.1351/pac199163121781"&gt;JCAMP-DX&lt;/a&gt;) were XML-based, but it's not. At best we'd expend a lot of effort learning about namespaces, schema, and HTTP response headers only to end up with an amorphous flat &lt;tt&gt;&amp;lt;spectrum&amp;gt;&lt;/tt&gt; tag containing freeform text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use JSON&lt;/strong&gt; We could encode our JCAMP-DX files as &lt;a href="http://www.json.org/js.html"&gt;JSON&lt;/a&gt;. JSON is a markup language like XML, but with the difference that it can be &lt;tt&gt;eval&lt;/tt&gt;ed directly by the JavaScript interpreter. This has the advantage that either a filename, or the actual data could be encoded. We could, in fact, create the entire object model for our spectrum, ready to be displayed, if we had software that could make the conversion from JCAMP-DX to JSON. This approach has the disadvantage that it could require significant amounts JavaScript code to be mixed in with our HTML, &lt;a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript"&gt;a less than ideal solution&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use the Object Tag&lt;/strong&gt; Given that none of the three options above are especially appealing, we might ask ourselves whether we've really tried everything possible to use plain old HTML to encode our data. More specifically, what if we were to use the object tag itself, without actually having a plugin?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;Encoding Custom Data Types With The Object Tag&lt;/h4&gt;

&lt;p&gt;The &lt;a href="http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.3"&gt;HTML 4 specification&lt;/a&gt; has this to say about the object tag:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;Most user agents have built-in mechanisms for rendering common data types such as text, GIF images, colors, fonts, and a handful of graphic elements. To render data types they don't support natively, user agents generally run external applications. The OBJECT element allows authors to control whether data should be rendered externally or by some program, specified by the author, that renders the data within the user agent.&lt;/p&gt;
    
    &lt;p&gt;In the most general case, an author may need to specify three types of information:&lt;/p&gt;
    
    &lt;ul&gt;
    &lt;li&gt;The implementation of the included object. For instance, if the included object is a clock applet, the author must indicate the location of the applet's executable code.&lt;/li&gt;
    &lt;li&gt;The data to be rendered. For instance, if the included object is a program that renders font data, the author must indicate the location of that data.&lt;/li&gt;
    &lt;li&gt;Additional values required by the object at run-time. For example, some applets may require initial values for parameters.&lt;/li&gt;
    &lt;/ul&gt;
    
    &lt;p&gt;The OBJECT element allows authors to specify all three types of data, but authors may not have to specify all three at once. For example, some objects may not require data (e.g., a self-contained applet that performs a small animation). Others may not require run-time initialization. Still others may not require additional implementation information, i.e., the user agent itself may already know how to render that type of data (e.g., GIF images).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, we could place a reference to a spectrum object in an HTML page with code like this:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;object&lt;/span&gt; &lt;span class="attribute"&gt;width&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;520&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;height&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;350&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;data&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;http://base-url/spectrum.jdx&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;After loading the document, we could have WebSpex walk the DOM looking for object tags that could be replaced with an instance of WebSpex. That instance could actually be placed inside the original object tag like this:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;object&lt;/span&gt; &lt;span class="attribute"&gt;width&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;520&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;height&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;350&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;data&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;http://base-url/spectrum.jdx&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;div&lt;/span&gt; &lt;span class="attribute"&gt;class&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;webspex&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
    &lt;span class="comment"&gt;&amp;lt;!-- WebSpex visual presentation --&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;div&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The HTML 4 documentation states that any content contained within object tags not recognized by the user agent will be rendered (fallback content). So dynamically inserting the div into the object tag as shown above would have the effect of giving the browser something to display in place of the object tag.&lt;/p&gt;

&lt;h4&gt;Advantages of Using This Approach&lt;/h4&gt;

&lt;p&gt;This approach has several advantages worth mentioning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It's fully compliant with the HTML 4 specification.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It provides a natural anchor point to attach both the custom data and the visual presentation of that data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It's pure HTML, requiring minimal mixing in of JavaScript content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Web spiders can be taught a single method to associate a spectrum with a URL, regardless of how the viewer is implemented.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It's technology-agnostic. This approach lets us implement WebSpex as a Java or Flash applet (or some other plugin technology) just as easily as a pure JavaScript UI. To change our viewer implementation, we just change a JavaScript file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It allows spectra to be inlined, or place directly into the HTML. Using a &lt;a href="http://en.wikipedia.org/wiki/Data:_URI_scheme"&gt;Data URI&lt;/a&gt;, we could replace "http://base-url/spectrum.jdx" with something like "data:chemical/x-jcamp-dx;base64,iVBORw0KGgoAA...". This would be important in those situations in which a public URL to a JCAMP file was not feasible and/or desirable. It could also accelerate the rendering of multiple spectra in the same page by eliminating the need to create a separate HTTP request for each file.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The method carries an imporant limitation: if a user has disabled JavaScript, they may see nothing to indicate a problem. We could address this issue by always placing fallback content in the object tag that would then be overwritten by the JavaScript code.&lt;/p&gt;

&lt;h4&gt;Implementation Detail&lt;/h4&gt;

&lt;p&gt;This approach relies on &lt;a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript"&gt;Onobtrusive JavaScript&lt;/a&gt; techniques to keep JavaScript as separate from HTML as possible. One way to implement such a scheme would be to include a single reference to the relevant JavaScript somewhere in the document, probably withing the &amp;lt;head&amp;gt; tag or right after the opening &amp;lt;body&amp;gt; tag:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;script&lt;/span&gt; &lt;span class="attribute"&gt;type&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;text/javascript&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;src&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;webspex.js&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;script&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The file webspex.js would then execute code to place a function into the document's &lt;tt&gt;onLoad&lt;/tt&gt; queue that would scan for object tags containing JCAMP-DX content and insert the needed viewer.&lt;/p&gt;

&lt;h4&gt;Previous Uses&lt;/h4&gt;

&lt;p&gt;I'm unaware of any previous applications of this technique, although is seems like something that may have been used before.&lt;/p&gt;

&lt;h4&gt;Conclusions&lt;/h4&gt;

&lt;p&gt;Encoding and displaying custom data types in HTML is possible by using the HTML 4 object tag coupled with client-side JavaScript to rewrite the DOM. It offers the potential to create HTML documents that are both human- and machine-readable. Although the approach described here was developed for the special case of spectroscopy data, it could in principle be used for any data type requiring a visual presentation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Image Credit: &lt;a href="http://flickr.com/photos/mdezemery/"&gt;mdezemery&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 24 Jul 2008 16:40:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:a859a6ea-6443-48ad-a35d-3f242546b252</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2008/07/24/building-webspex-putting-custom-data-types-in-their-place</link>
      <category>Tools</category>
      <category>webspex</category>
      <category>jcamp</category>
      <category>dx</category>
      <category>objecttag</category>
      <category>html4</category>
      <category>javascript</category>
      <category>flash</category>
      <category>java</category>
      <category>plugin</category>
    </item>
    <item>
      <title>Demystifying Java Applets, Part 1: Cross-Browser, Standards-Compliant, Pure HTML Deployment Using the Object Tag</title>
      <description>&lt;p&gt;&lt;a href="http://flickr.com/photos/oskay/437341128/"&gt;&lt;img src="http://depth-first.com/demo/20080220/components.jpg" align="right"&gt;&lt;/img&gt;&lt;/a&gt;A &lt;a href="http://today.java.net/pub/pq/89"&gt;2006 survey on java.net&lt;/a&gt; posed a simple question to developers: What's wrong with applets? By a significant margin, the number one complaint was that they are "too hard to deploy." This article, the first in a series, takes a look at the issue of Java applet deployment and in particular how using the &amp;lt;object&amp;gt; tag can radically simplify and enhance both the developer and end user experience.&lt;/p&gt;

&lt;h4&gt;Applets? You Must Be Joking!&lt;/h4&gt;

&lt;p&gt;Applets got a well-deserved bad reputation in the early days of Java. They were slow, difficult to deploy across browsers, and over-hyped. The situation has signficantly changed for the better, but the bad reputation lingers.&lt;/p&gt;

&lt;p&gt;There are many situations in which applets are inappropriate. The most important of these is when simple interactivity can be achieved through HTML or JavaScript (Ajax).&lt;/p&gt;

&lt;p&gt;But in many situations, HTML and JavaScript make a poor platform choice. As a specific example, consider &lt;a href="http://depth-first.com/articles/2007/11/27/chemwriter-chemical-structures-and-the-web"&gt;Web-based chemical structure editors&lt;/a&gt;. The high level of &lt;a href="http://depth-first.com/articles/2008/02/14/the-art-and-science-of-chemical-structure-diagrams-chemwriter-as-chemically-aware-vector-graphics-system"&gt;graphical manipulation&lt;/a&gt;, sophistication of data processing, and responsiveness required by these components, coupled by their ubiquity, means that it will be a long time indeed before Ajax (or Flash for that matter) is up to the challenge - and they may never be, given their design constraints.&lt;/p&gt;

&lt;p&gt;For a large number of specialized Web components, applets are the only platform.&lt;/p&gt;

&lt;p&gt;Regarding the "uncool factor", it's worth pointing out that not more than four years ago JavaScript was one of the most loathed, ridiculed, and ignored technologies around. Now it &lt;a href="http://www.paulgraham.com/web20.html"&gt;finally works&lt;/a&gt; - meaning it's reliable enough to be used on all modern browsers. The result is Ajax and a host of interactive Web technologies that played a major role in redefining what the Web was all about.&lt;/p&gt;

&lt;p&gt;Whether a similar renaissance happens for applets is anybody's guess, but most of the prerequisites have already been met.&lt;/p&gt;

&lt;h4&gt;Deployment with the &lt;tt&gt;&amp;lt;applet&amp;gt;&lt;/tt&gt; Tag&lt;/h4&gt;

&lt;p&gt;If you decide to develop Web applications with applets, a major consideration will eventually become how to deploy them. Unfortunately, a bewildering array of often contradictory advice is available on the subject - most of it outdated.&lt;/p&gt;

&lt;p&gt;Many sources recommend using the &lt;tt&gt;&amp;lt;applet&amp;gt;&lt;/tt&gt; tag. It's the oldest method, and will generally work on most browsers. For example, to deploy my company's structure editor applet &lt;a href="http://metamolecular.com/products/chemwriter"&gt;ChemWriter&lt;/a&gt;, the following code could be used:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;applet&lt;/span&gt; &lt;span class="attribute"&gt;code&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;com/metamolecular/chemwriter/applet/EditorApplet.class&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
        &lt;span class="attribute"&gt;archive&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;/path/to/applets/chemwriter.jar&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
        &lt;span class="attribute"&gt;width&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;600&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;height&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;300&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;persistState&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;false&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;applet&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Unfortunately, the &lt;tt&gt;&amp;lt;applet&amp;gt;&lt;/tt&gt; tag has some very important strikes against it. The first is that its use is &lt;a href="http://www.w3.org/TR/html401/struct/objects.html#h-13.4"&gt;now deprecated&lt;/a&gt; in HTML. In other words, whatever support browsers now have for it is living on borrowed time.&lt;/p&gt;

&lt;p&gt;The second problem with the &lt;tt&gt;&amp;lt;applet&amp;gt;&lt;/tt&gt; tag is an insidious bug in Internet Explorer (as if there were any other kind). Most hardware suppliers pre-install Java onto their Microsoft-based machines, which is a good thing. The bad thing is that at least one major manufacturer disables the Java console in IE 7 at the same time. Under IE 7, disabling the Java console renders all &lt;tt&gt;&amp;lt;applet&amp;gt;&lt;/tt&gt; tags invisible. Counterintuitive as it may seem, this is what happens. The insidious part is that perplexed users &lt;em&gt;know&lt;/em&gt; they have Java installed because they can see the plug-in, are being told by IE that it's active, can find some applets that *do* work and - well, you get the idea.&lt;/p&gt;

&lt;p&gt;The third problem with the &lt;tt&gt;&amp;lt;applet&amp;gt;&lt;/tt&gt; tag is that, by itself, it has no mechanism to indicate which version of Java is required. This can be a very important consideration for applets that take advantage of the major advances in functionality and performance of the Java platform in recent years.&lt;/p&gt;

&lt;h4&gt;A Better Way: Deployment with the &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; Tag&lt;/h4&gt;

&lt;p&gt;All major browsers support the &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; tag, and this is the &lt;a href="http://ww2.cs.fsu.edu/~steele/XHTML/appletObject.html"&gt;preferred method for deploying applets&lt;/a&gt;. Provided that Internet Explorer's peculiarities are accounted for, a single piece of valid HTML can render applets on all major browsers including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IE 6/7&lt;/li&gt;
&lt;li&gt;Firefox 1.5/2&lt;/li&gt;
&lt;li&gt;Safari&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a specific example using ChemWriter, the &lt;tt&gt;&amp;lt;applet&amp;gt;&lt;/tt&gt; tag above can be re-written with the &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; tag:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="comment"&gt;&amp;lt;!--[if !IE]&amp;gt; --&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;object&lt;/span&gt; &lt;span class="attribute"&gt;classid&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;java:com/metamolecular/chemwriter/applet/EditorApplet.class&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; 
              &lt;span class="attribute"&gt;type&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;application/x-java-applet&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
              &lt;span class="attribute"&gt;archive&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;/path/to/applets/chemwriter.jar&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; 
              &lt;span class="attribute"&gt;height&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;350&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;width&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;550&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;code&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;com/metamolecular/chemwriter/applet/EditorApplet.class&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="comment"&gt;&amp;lt;!-- For Konqueror --&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;archive&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;/path/to/applets/chemwriter.jar&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;persistState&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;value&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;false&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;center&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;img&lt;/span&gt; &lt;span class="attribute"&gt;src&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;/path/to/images/chemwriter_logo.png&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;p&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;strong&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;ChemWriter content requires Java 1.4.2 or higher, which your browser does not appear to have.&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;strong&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;p&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;p&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;a&lt;/span&gt; &lt;span class="attribute"&gt;href&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;http://www.java.com/en/download/index.jsp&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;Get the latest Java Plug-in.&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;a&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;p&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;center&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="comment"&gt;&amp;lt;!--&amp;lt;![endif]--&amp;gt;&lt;/span&gt;
&lt;span class="comment"&gt;&amp;lt;!--[if IE]&amp;gt;
&amp;lt;object classid=&amp;quot;clsid:8AD9C840-044E-11D1-B3E9-00805F499D93&amp;quot; 
                codebase=&amp;quot;http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab#Version=1,4,0,0&amp;quot;
                height=&amp;quot;350&amp;quot; width=&amp;quot;550&amp;quot; &amp;gt; 
  &amp;lt;param name=&amp;quot;code&amp;quot; value=&amp;quot;com/metamolecular/chemwriter/applet/EditorApplet.class&amp;quot; /&amp;gt;
  &amp;lt;param name=&amp;quot;archive&amp;quot; value=&amp;quot;/path/to/applets/chemwriter.jar&amp;quot; /&amp;gt;
  &amp;lt;param name=&amp;quot;persistState&amp;quot; value=&amp;quot;false&amp;quot; /&amp;gt;
  &amp;lt;center&amp;gt;
    &amp;lt;img src=&amp;quot;/path/to/images/chemwriter_logo.png&amp;quot; /&amp;gt;
    &amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;ChemWriter content requires Java 1.4.2 or higher, which your browser does not appear to have.&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt;&amp;lt;a href=&amp;quot;http://www.java.com/en/download/index.jsp&amp;quot;&amp;gt;Get the latest Java Plug-in.&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
  &amp;lt;/center&amp;gt;
&amp;lt;/object&amp;gt;
&amp;lt;![endif]--&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Before explaining the code, here's what the verbosity buys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It works with both IE 6/7 &lt;em&gt;and&lt;/em&gt; standards-compliant browsers such as Firefox.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It avoids the use of &lt;a href="http://depth-first.com/articles/2007/11/20/write-once-run-anywhere-simplifying-java-applet-deployment"&gt;JavaScript JVM detection methods&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It prompts the user to download the correct JVM, &lt;em&gt;without immediately directing them away from the current page&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Firefox and IE users can opt to install the Java plugin without ever leaving their current page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It works in IE 7 with the Java console disabled.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;You've Got Some 'Splainin' to Do&lt;/h4&gt;

&lt;p&gt;The code above is based on documentation found on &lt;a href="http://ww2.cs.fsu.edu/~steele/XHTML/appletObject.html"&gt;this site&lt;/a&gt;, which also details the meaning of the &lt;tt&gt;codebase&lt;/tt&gt; and &lt;tt&gt;classid&lt;/tt&gt; attributes.&lt;/p&gt;

&lt;p&gt;The main idea is that Internet Explorer handles the &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; tag in its own idiosyncratic, lovable way. Most of this difference is in the &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; element itself and the &lt;tt&gt;classid&lt;/tt&gt; attribute in particular. By taking advantage of Internet Explorer's support for &lt;a href="http://msdn2.microsoft.com/en-us/library/ms537512.aspx"&gt;conditional comments&lt;/a&gt;, we can handle both IE and the rest with one chunk of HTML.&lt;/p&gt;

&lt;h4&gt;A Live Demonstration&lt;/h4&gt;

&lt;p&gt;For a live demonstration of the above technique, see the &lt;a href="http://metamolecular.com/products/chemwriter/"&gt;ChemWriter Home Page&lt;/a&gt;. If you have Java 1.4.2 or higher installed and activated in your browser, you'll see the most recent version of the ChemWriter editor applet. If not, you'll see the ChemWriter logo and a link to install Java. Firefox and IE will also display an "Install Plugin" bar at the top of the browser for in-place installation of the JVM.&lt;/p&gt;

&lt;h4&gt;Click to Activate: Working Around Eolas&lt;/h4&gt;

&lt;p&gt;A &lt;a href="http://depth-first.com/articles/2007/11/02/eolas-and-jactivating-working-around-a-workaround"&gt;recent Depth-First article&lt;/a&gt; discussed the problem that IE 6 and 7 have involving a "click to activate" (or "Eolas") message that appears with applets and all other browser plugins. To eliminate this issue, the &lt;a href="http://metamolecular.com/products/chemwriter/"&gt;ChemWriter Home Page&lt;/a&gt; uses the excellent &lt;a href="http://jactivating.sf.net/"&gt;jActivating library&lt;/a&gt;. This JavaScript library, which is included in the HTML &lt;tt&gt;&amp;lt;head&amp;gt;&lt;/tt&gt; tag, obviates the need to write the &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; tag using JavaScript. All that's left is pure, standards-compliant HTML to debug, deploy, and maintain.&lt;/p&gt;

&lt;h4&gt;Conclusions&lt;/h4&gt;

&lt;p&gt;Applet deployment, like Java itself, has come a long way in the last ten years. This article has shown one method to deploy applets into highly heterogeneous computing environments with relatively little effort.&lt;/p&gt;

&lt;p&gt;But deployment is only one aspect of interactive Web development using applets. Future articles will discuss some of the others.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Image Credit: &lt;a href="http://flickr.com/photos/oskay/"&gt;oskay&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 20 Feb 2008 09:41:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:939270fa-0bf7-4e28-8991-07c45a8a03f1</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2008/02/20/demystifying-java-applets-part-1-cross-browser-standards-compliant-pure-html-deployment-using-the-object-tag</link>
      <category>Tools</category>
      <category>java</category>
      <category>applet</category>
      <category>chemwriter</category>
      <category>deploy</category>
      <category>objecttag</category>
      <category>applettag</category>
      <category>jactivating</category>
      <category>eolas</category>
    </item>
  </channel>
</rss>
