Solved

How can I use JavaScript from within my Java Applet?

Posted on 2004-04-29
3
192 Views
Last Modified: 2010-03-31
Hello,
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.
Thanks,
Adam
0
Comment
Question by:aj72886
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
Webstorm earned 100 total points
ID: 10951910
Hi aj72886,

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

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

import netscape.javascript.JSObject;

...
   try
      {
      JSObject win = JSObject.getWindow(this);
      win.eval("alert('javascript called');");  // <-- javascript code
      }
    catch (Exception e)
      {
      System.out.println("Exception:Javascript");
      e.printStackTrace();
       }

Or you can see  http://www.rgagnon.com/javadetails/java-0172.html
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
String array comparison 4 56
jmss example java 2 48
Eclipse for Java EE development 2 67
Java pass by reference 3 73
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question