views:

238

answers:

3

I'm working with an existing Java codebase which, while it can be invoked from an HTML page using an <APPLET> tag, does not actually subclass the Applet class. The same jars are also used in a non-browser context, so they did not subclass Applet.

Now I need to communicate some values from Java back to the Javascript of the invoking page. Normally one would do this using JSObject, but so far as I can one has to use JSObject.getWindow which only works for subclasses of Applet.

Is there either:

  • a way to use JSObject from something which isn't an Applet subclass?
  • some other mechanism to communicate back to the Javascript of the invoking page?
+3  A: 

Call JSObject.getWindow(this) in the applet. Then pass the JSObject into the code that needs it in the usual fashion.

Tom Hawtin - tackline
+2  A: 

I think you're actually going to need to implement an applet in a jar file to handle the communication between your code and the browser itself. Perhaps just use the non-applet jar as a class lib and make the applet jar a simple wrapper that proxies your calls between the browser and the Java code.

jsight
+1  A: 

What's wrong with returning a value?

From Javascript You can access the Java-object by using getElementById("id-of-embed-tag"). Then you can invoke any public method on that object. The Java object returned by that method will be available to your Javascript code.

Itay
Thats an approach I had not considered. I'd end up polling from the Javascript until something changes, but that might work.
DGentry