Solved

How can I use JavaScript from within my Java Applet?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 134
bitbucket vs gitbucket 3 58
Cipher Configuration on Apache HTTPD 4 53
MySQL  on Tomcat 8 30
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 …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

863 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

27 Experts available now in Live!

Get 1:1 Help Now