Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Mac-specific Java-Javascript communication error

Hi,

We just recently refactored some code in an applet that was written in Java 1.4. I confirmed that the Java 1.6 version of the applet runs fine within X11 on my Mac. However, when I try to call the applet within a Web page with the following invocation:

<applet
code="com.ace.lewissketch.LewisSketch.class"
name="responseApplet"
codebase="/nosession/lewis/"
archive="LewisSketch.jar"
width="450"
height="320" >
</applet>
<script type="text/javascript">
document.responseApplet.setMol(getMol());
</script>


on my Mac, I get an error, "Result of expression 'document.responseApplet.setMol' [undefined] is not a function." This happens on both Safari 5 and Firefox 3. However, in Firefox on Linux and MSIE on a PC, the applet runs just fine. The Java 1.4 version of the applet also runs just fine on my Mac. So the problem is Mac-specific and specific to the new version of the applet. Any ideas how to solve or work around this problem?

MacBook Pro, Mac OS X (10.5.8)

Posted on Jul 6, 2010 9:05 AM

Reply
6 replies

Jul 6, 2010 9:54 AM in response to Robert Grossman

Strictly speaking, better might be:


document.getElementsByName('responseApplet')[0].selMol(getMol());


The problem is that the 'applet' tag is deprecated in HTML4 and unsupported in XHTML (in favor of the 'object' tag). The result is that most browsers still honor the tag, but Javascript engine may or may not do the normal expansion of the names as properties in the document object. What's even more confusing is that the 'embeds' property of a document is supposed to be an array of all the 'object' tags in the HTML, but browsers that use / used the 'embed' tag also include those in the same array. Ugh.

You might also be able to get away with:


document.embeds[0].setMol(getMol());


... and this will probably work with most browsers, though deprecated:


document.applets[0].setMol(getMol());

Jul 6, 2010 10:44 AM in response to J D McIninch

Thanks for the suggestions. As it turns out, the setMol() call is a red herring. I've set up a very simple page at http://epoch.uky.edu:9080/epoch-plugin/public/lewisTest.jsp that does not invoke setMol(), and it displays the same behavior: loads on a PC, fails to load on a Mac, but the older Java 1.4 applet, which is invoked by a nearly identical page at http://epoch.uky.edu/epoch-plugin/public/lewisTest.jsp , loads just fine on Mac.

The fact that the Java 1.4 applet loads and the Java 1.6 applet fails to load (although it runs fine in X11) is what's really puzzling me, along with the specificity of the problem to Macs.

Message was edited by: Robert Grossman

Jul 7, 2010 1:25 PM in response to Robert Grossman

I have a bit more information. First, the Java Preferences panel of my Mac shows that it has Java SE 6. It was second in the list, but moving it to the top of the list had no effect.

Second, Safari will run the applet if we compile it with a Java 1.5 compiler. It just won't run it if we compile it with a Java 1.6 compiler.

Third, X11 will run the applet when it is compiled with a Java 1.6 compiler. Only Safari won't.

Fourth, if I look at the Java console after the applet fails to load, it says,

basic: Exception: java.lang.UnsupportedClassVersionError: Bad version number in .class file

This error suggests that I don't have Java 1.6. But I do. Or at least, Java Preferences tells me I do.

Google searches on the error message have not been fruitful. Any help that you can offer would be appreciated.

Mac-specific Java-Javascript communication error

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.