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 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.