Search code examples
javaxhtmlappletstandards-compliance

Using the standard OBJECT tag, how can I display a java applet with automatic prompts to install Java and with fallback content?


This is the code i'm currently using: (note - %s is replaced on the server side)

<!--[if !IE]>-->
<object
        type="application/x-java-applet"
        width="300" height="300"
>
<!--<![endif]-->
<!--[if IE]>
<object
        classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
        codebase="http://java.sun.com/update/1.6.0/jinstall-6u22-windows-i586.cab"
        type="application/x-java-applet"
        width="300" height="300"
>
<!--><!-- <![endif]-->
        <param name="codebase" value="/media/vnc/" >
        <param name="archive" value="TightVncViewer.jar" />
        <param name="code" value="com.tightvnc.vncviewer.VncViewer" />

        <param name="port" value="%s" />
        <param name="Open New Window" value="yes" />
</object>

When Java is installed, this works perfectly in both IE and Firefox. When Java is not installed, IE and Firefox both correctly prompt for an autodownload of Java 1.6 from the codebase line. (IE via the activex url given firefox via the Plugin Finder Service)

Now, suppose I want fallback content to be shown if the plugin isn't installed, say a simple message like "Get Java". From reading the specs, i'd assume this should not change the plugin finding prompt - that is, rendering the fallback should be seen as a failure to render the object tag. Thus, I should still get the plugin finder service prompting me to install Java. Instead, simply adding a single character to the innerHTML of the object element causes Firefox to no longer prompt. Test this by visiting data:text/html,<object type='application/x-java-applet'>Java failed to load</object>.

How can I keep firefox prompting to install Java while providing fallback content?

URL to test Firefox's Java Plugin Finder Service: data:text/html,<object type='application/x-java-applet'/>


Solution

  • How can I keep firefox prompting to install Java while providing fallback content?

    Edit/make the VncViewer applet start() method to set a Javascript variable. From Javascript check the variable's existence with setTimeout or setInterval after some seconds. If it fails to appear then java is not working so alert the user to get the latest java runtime from java.com. You could even use the DOM to insert a clickable link.

    Should work for any browser and the fallback text will appear. The HTML is simpler too:-

    <object type="application/x-java-applet" width="300" height="300">
        <param name="codebase" value="/media/vnc/" />
        <param name="code" value="com.tightvnc.vncviewer.VncViewer" />
        <param name="archive" value="TightVncViewer.jar" />
        <param name="mayscript" value="true" />
        Java failed to load
    </object>
    

    Notes

    classid, as used for IE in the question, finds the highest user installed java version. If the found version is less than 1.6 then the codebase attribute prompts the user to download 1.6. However, if the latest version was 1.7 then security bugfixes could be missed, so wouldn't it be better to prompt for the latest version.

    From java plugin 1.5.0_06 (Dec 2005) the highest user installed java version is selected automatically anyway. So the classid used in the question seems somewhat irrelevant in 2011. Whether codebase would work on its own I don't know.

    In HTML4 the classid and codebase object attributes are supposed to represent the implementation location (e.g. the applet itself), not the java version. So the IE system looks completely non standard.

    In HTML5 classid and codebase attributes are obsolete.

    The use of "code" attribute or parameter does not appear in HTML4 object spec, nor HTML5.

    Could not get the HTML4/5 "data" attribute working in IE8 nor FF5.

    All in all it looks a right mess, and hardly surprising that oracle suggest using the deprecated old applet tag instead of the object tag.