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

11,057

Solution 1

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.

Solution 2

Check here: https://eyeasme.com/Shayne/XHTML/appletObject.html

Question: Why there is only one closing tag? Non-IE browsers will see two opening OBJECT tags [yes, second one won't work because of the unrecognizable value in CLASSID attribute], and they will be accompanied by only one closing counterpart.

EDIT 2: Unfortunately, I couldn't make the method described in that page work on Chrome. All other browsers [FF, IE, Safari and Opera - latest versions] work just fine, except Chrome - it doesn't even load the applet/object.

Solution 3

Seems to me that using [if IE] classid and codebase attributes complicate the HTML. Also, they are only used to direct the user if Java is not installed. Instead, why not use a setTimeout in JS to call a method in the applet after some seconds, and if it doesn't respond then use JS to advise the user action. That simplifies the object code to something like this:-

<p>
<object type="application/x-java-applet"
    name="accessName" 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="scriptable" value="true" />
    <param name="mayscript" value="true" />
    <param name="port" value="%s" />
    <param name="Open New Window" value="yes" />
</object>
</p>

If the applet has to call JS, the mayscript param is needed for Java plugins before 1.6.0.10. The scriptable param is still required according to javadocs 1.6.0.21 if JS needs to call the applet. However, in one of my tests with 1.6.0.24 for a signed applet, IE8 called it OK from JS without scriptable being set true. For the above applet, you don't need "mayscript", or the author would have included it, but you might need "scriptable" for any setTimeout call.

Share:
11,057
EB.
Author by

EB.

Updated on June 04, 2022

Comments

  • EB.
    EB. almost 2 years

    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'/>