Solved

How can I use JavaScript from within my Java Applet?

Posted on 2004-04-29
3
186 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now