How do I communicate with an applet from JavaScript?

Sameer Tyagi

You can use use JavaScript to diretly call public methods in the applet or access public variables. JavaScript treats the embedded applet as an object. In the applet tag give the applet a name (for Netscape to recognize the applet), and an Id (for IE to recognize the applet).

Consider the example below where the applet has 2 methods public void increment() which increments a counter and public void decrement() which decrements the counter.

The HTML page would look something like :

<HEAD>
<SCRIPT LANGUAGE="JavaScript">

</SCRIPT>

</HEAD>


<APPLET CODE="MyApplet.class" 
   width=200 height=200 
   name=counter ID=counter>
</APPLET>


<FORM NAME>
<INPUT TYPE="BUTTON" VALUE="Increment"  
  OnClick="incrementIt();">
<INPUT TYPE="BUTTON" VALUE="Decrement" 
  OnClick="decrementIt();">
</FORM>
Note: There are issues regarding JavaScript - Java communications on the Mac. They don't work.

For additional information see http://www.codeproject.com/jscript/javatojs.asp.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact