Developing with ChemWriter

ChemWriter Deployment

Last Updated on Thursday, March 06, 2008.

Overview

ChemWriter applets are deployed using the HTML 4 compliant <object> tag. Recognized by all major browsers, this tag provides a mechanism not only to deploy ChemWriter, but to deliver its Java plugin dependency to users who don’t currently have it. Deployment on Internet Explorer requires two workarounds specific to this browser family.


Using the <object> Tag

The listing below illustrates the best-practices method for deploying ChemWriter applets. It consists of four main parts:

  1. An Internet Explorer conditional comment header and opening <object> tag.
  2. The <params> block inlcluding the licenseKey parameter.
  3. A nested, linked image to be displayed if the Java plugin is either not found or disabled.
  4. The closing <object> tag.
<!--[if IE]><object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab#Version=1,4,0,0"
width="520" height="350"><script>/*<![endif]--><script type="text/javascript">/**/</script>
<!--[if !IE]><!-->
<object type="application/x-java-applet;version=1.4.2" width="520" height="350">
<!--<![endif]-->
  <param name="code" value="com/metamolecular/chemwriter/applet/EditorApplet.class">
  <param name="archive" value="http://metamolecular.com/applets/chemwriter.jar">
  <param name="persistState" value="false">
  <param name="licenseKey" value="D7D4-1D2B-B43C-078F-ACF9-F1F6">
  <a href="/java/">
    <img src="/images/java/no_java_display.png"/>
  </a>
</object>

The above code is based on cross-browser approaches for deploying Adobe Flash™ content. Although less commonly used for Java applets, the concepts are analogous. This particular ChemWriter deployment method has been tested on Internet Explorer 6 and 7, Firefox 1.x and 2.x, and Safari 3.

Internet Explorer Conditional Comments

Internet Explorer (IE) implements the <object> tag through a mechanism not used by other browsers, requiring special treatment. A lightweight approach to doing this is possible with IE-specific conditional comments. The feature is used to tailor the opening <object> tag for use on IE 6/7. A second conditional comment block is used to prevent IE from loading the <object> opening tag twice. Browsers other than IE will not interpret any of the code contained within the comments blocks.

The <object> tag makes it possible to specify the exact version of the Java plugin needed to view content. Although Java 1.4.2 or higher can be used with ChemWriter, future versions may be based on a more recent version of Java. Changing the <object> tag makes it possible to update clients seamlessly should that occur.

Java Plugin Failsafe

If a client lacks the correct version of the Java plugin, or if the plugin is disabled, the <object> tag provides a failsafe mechanism. HTML nested within the <object> tag and after the <parameters> elements will be rendered in the event that the plugin specified by the <object> tag can not be found. More

Avoiding “Click to Activate” Message

As a result of losing the Eolas Patent Case, Microsoft was forced to change the way that it implements the <object> tag in IE. Instead of being active on loading, browser plugins in IE need to be activated first by the user. This results in a “Click to activate and use this control” message.

A few approaches to this problem have been developed. In one, Javascript’s document.write method is used to write the <object> tag into the browser dynamicall. One disadvantage of this approach is that if a user has disabled Javascript, they will see nothing - not even a failsafe to indicate a problem has occurred. Another disadvantage is that this method requires replacing HTML markup with Javascript code.

A more convenient approach is to use the jActivating library. jActivating is a small, freely-available Javascript library that re-writes the <object> tag automatically on IE and Opera browsers, circumventing the Eolas behavior. Using jActivating consists of nothing more than including the library within in the <head> tag.

To date, Opera is the only other major browser to have changed the way in which plugin content is displayed as a result of the Eolas ruling. It is unclear whether Firefox and Safari will be forced to follow.