DGentry
DGentry

Reputation: 16258

Java <-> Javascript for non-Applets?

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:

Upvotes: 3

Views: 448

Answers (3)

Itay Maman
Itay Maman

Reputation: 30723

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.

Upvotes: 1

jsight
jsight

Reputation: 28409

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.

Upvotes: 2

Tom Hawtin - tackline
Tom Hawtin - tackline

Reputation: 147124

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

Upvotes: 3

Related Questions