jQuery in Action, 2nd edition*
The moose likes Applets and the fly likes call java method from javascript when using java plug-in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "call java method from javascript when using java plug-in" Watch "call java method from javascript when using java plug-in" New topic
Author

call java method from javascript when using java plug-in

arul narayan
Greenhorn

Joined: Sep 26, 2000
Posts: 17
I am able to call java method from javascript when i use the browser's JVM.
But when i use the java plug-in, and call the java method, I get:"error:document.myApplet not an object". How do I call the java method in this case?
Given below is the code snippet for better understanding of the problem or to find out whether I am missing something here. Thanks.
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "0" HEIGHT = "0" codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-1.2.2-win32.cab#Version=1,2,2,0">
<PARAM NAME="code" VALUE="HelloWorld.class">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="name" VALUE="myApplet">
<PARAM NAME="scriptable" VALUE="true">
</OBJECT>
<input name=Submit type=submit value="test" onClick=document.myApplet.callMethod()>
</p>

arul.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
As far as I am aware, this is not possible. I needed to do it some months ago, and wrote some diagnostic JavaScript to traverse the whole JavaScript object tree, and did not find any mention of my applet.
Applets in a Plug-in can call JavaScript, but the reverse seems just not possible. In the end I had to make my applet sit in a thread, waiting and polling a JavaScript variable until the JavaScript set it.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
xavier gagneur
Greenhorn

Joined: Jul 26, 2001
Posts: 3
Originally posted by Frank Carver:
As far as I am aware, this is not possible. I needed to do it some months ago, and wrote some diagnostic JavaScript to traverse the whole JavaScript object tree, and did not find any mention of my applet.
Applets in a Plug-in can call JavaScript, but the reverse seems just not possible. In the end I had to make my applet sit in a thread, waiting and polling a JavaScript variable until the JavaScript set it.

Hi,
I can call Java Methode in Applet using plug-in but I can't Call Javascript from Java.
That is my problem! Just see that...
///////////////////
//HTML SOURCE
<html>
<HEAD>
<SCRIPT code="JavaScript">
function writeHtml(nbr){
document.writehtml.writeHtml(nbr);
};
</SCRIPT>
</HEAD>
<BODY>
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="300" height="300" codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win.cab#Version=1,3,0,0"
name="writehtml">
<PARAM NAME=CODE VALUE=HtmlWriter>
<PARAM NAME="codebase" VALUE=".">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="true">
<PARAM NAME="MAYSCRIPT" VALUE="true">
</OBJECT>
<FORM name="resto">
Nombre de lignes a g�n�rer : <input name="result" type="text" value="5"><BR>
<input type="button" onclick="javasript:writeHtml(document.resto.result.value)" value="OK">
</FORM>
</BODY>
</HTML>
//////////////////////
//JAVA JAPPLET SOURCE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import netscape.javascript.*;
public class HtmlWriter extends JApplet{
JSObject win = null;
public void paint(Graphics g){
g.setColor(Color.black);
g.drawString("APPLET RUN...", 15,35);
}

public void writeHtml(String Nombre){
win.eval("alert('TEST2');"); // CRASH HERE!!!
}
public void init(){
win = JSObject.getWindow(this); //OK
win.eval("alert('TEST');"); //No PROBLEMES HERE
repaint();
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: call java method from javascript when using java plug-in
 
Similar Threads
Is it a Netscape bug?
With Java Plug-in, document.applets.length returns 0
call java method from javascript when using java plug-in
Problem while Invoking Applet's method from javascript
Plug-in Versions and Sun Download