views:

125

answers:

3

Hi, I wanted to know if I can write something on the HTML page containing my Java applet from within the applet.

More generally, what interactions are possible between these two?

Thanks.

A: 

A java applet can call javascript functions.

FWH
and how might this be done?
Mike Cooper
It seems this:getAppletContext().showDocument(new URL("javascript:doSomething()"));could be the answer.Is there any other way?
Mohammad Alinia
+1  A: 

You could use the JSObject.

Sun: java to javascript communication

zesc
It's called LiveConnect (JavaScript used to be called LiveScript. Easy to google.
Tom Hawtin - tackline
+2  A: 

From within your java applet

 // object to allow applet to invoke Javascript methods
protected static JSObject appletWindowJSObject = null;

appletWindowJSObject = JSObject.getWindow(this);

 //Call your javascript method on the page and pass it something
 appletWindowJSObject.call("myJavascriptMethod", "This is what I am passing");

You can then use javascript to manipulate the html page as usual.

May also need to include the mayscript parameter when declaring the applet, not sure if this is needed anymore or not.

Knife-Action-Jesus