How To Send Javascript Variables To Java Applet
Solution 1:
Your applet should have a public method , for example receiveData() :
publicvoidreceiveData(String dataFromJS)
{
//Do what you need with your data
}
Let's say you have something like that in your web page :
<applet id ="appletID" name="myApplet" ... ></applet>
In your javascript you just have to call the applet public method like this :
var myApp = document.applets['myApplet'];
myApp.receiveData(taxElem.innerHTML + subtotalElem.innerHTML);
The previous example will send the taxElem and subtotalElem content to the applet.
To send data from Applet to JS you sould use JSObject in your applet
Solution 2:
You can use netscape.javascript.JSObject for Java-to-JS direction or reference the applet by its id for JS-to-Java.
See here for detailed example : http://rostislav-matl.blogspot.com/2011/10/java-applets-building-with-maven.html
Solution 3:
The most reliable way to do this is to open a new page with the parameters encoded in the URL, then write those parameters as into an applet element as param
elements. (Though +1 to each of the other answers.)
Post a Comment for "How To Send Javascript Variables To Java Applet"