• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

How can I use JavaScript from within my Java Applet?

Apparently using the MAYSCRIPT param in the Applet HTML tag you can allow the Applet to use JavaScript. I was wondering how to go about doing this.
I want to be able to close the browser window from within the applet and using JavaScript seems like a good way.
1 Solution
Hi aj72886,

You can call an applet method from javascript, for example :
<applet code="MaClasse.class" name="my"></applet>
<input type=button value="Call Javascript"  
       onclick="if (my) {my.callJavascript();}">
the javascript code call a method named "callJavascript".

And calling javascript from a java applet is browser specific. For Netscape :

import netscape.javascript.JSObject;

      JSObject win = JSObject.getWindow(this);
      win.eval("alert('javascript called');");  // <-- javascript code
    catch (Exception e)

Or you can see  http://www.rgagnon.com/javadetails/java-0172.html
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now