javaappletliveconnect

Can a java applet manipulate the HTML page containing it?


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.


Solution

  • 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.