Solved

How can I use JavaScript from within my Java Applet?

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate jars 4 57
eclipse buid path vs tomcat lib path 10 37
Where to place postgres JDBC driver jar on tomcat 8 25
How to fix  socket closed error 11 22
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…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.

735 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