我正在使用现有的 Java 代码库,虽然可以使用
现在我需要将一些值从 Java 传送回调用页面的 Javascript。 通常人们会使用 JSObject 来做到这一点,但就我所知,人们必须使用 JSObject.getWindow ,它只适用于 Applet 的子类。
是否有:
- 一种从不是 Applet 子类的东西中使用 JSObject 的方法?
- 是否有其他机制可以与调用页面的 Javascript 进行通信?
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)
在小程序中调用
JSObject.getWindow(this)
。 然后以通常的方式将JSObject
传递到需要它的代码中。Call
JSObject.getWindow(this)
in the applet. Then pass theJSObject
into the code that needs it in the usual fashion.我认为您实际上需要在 jar 文件中实现一个小程序来处理代码和浏览器本身之间的通信。 也许只需使用非 applet jar 作为类库,并使 applet jar 成为一个简单的包装器,代理浏览器和 Java 代码之间的调用。
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.
返回值有什么问题?
从 Javascript 您可以使用 getElementById("id-of-embed-tag") 访问 Java 对象。
然后您可以调用该对象上的任何公共方法。 该方法返回的 Java 对象将可供您的 Javascript 代码使用。
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.