?
Solved

How can I use JavaScript from within my Java Applet?

Posted on 2004-04-29
3
Medium Priority
?
194 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

764 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