1. javascript call java applet: http://www.rgagnon.com/javadetails/java-0170.html
* make the variable you want to call public in the applet.
* in javascript just: document.myapplet.myfunction(some parametres);
2.1 java applet call variable or function defined in javascript:
* You can try an easy method, by calling a specially crafted URL using the showDocument() method, like this :
getAppletContext().showDocument(new URL("javascript:alert(Hello World);));
This doesn't work anymore using Internet Explorer as of a certain IE update from Microsoft dated some time ago this year, so it is easily broken.
* You can use the LiveConnect objects that are implemented in IE on Windows, Mozilla/Firefox on anything, Safari on Mac, etc.. it works almost everywhere.
For this you have to declare that your applet MAYSCRIPT, by adding a special parameter in the OBJECT/EMBED tag in your web page. (google for it if you need examples).
Then you have to add the "jaws.jar" (or "plugin.jar" if there's no jaws.jar) from the lib of the JRE to compile your Applet.
This jar should include the LiveConnext classes, and netscape.javascript.JSObject is the one you need.
Then You can then do something like this to achieve the same as solution one above :
JSObject browserWindow = JSObject.getWindow(this); //here 'this' is the JApplet
browserWindow.eval(buffer.toString());
Or you can navigate the DOM javascript tree of the WebPage using the methods of JSObject. (google for it if you need more info).
2.2 java applet call variable defined in html:
Just use the parametre of applet, for example:
Wednesday, 5 March 2008
java applet <> javascript
at 12:39
labels: howto, java, JavaScript
Subscribe to:
Post Comments (Atom)
1 comment:
Post a Comment