Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

call java method from javascript when using java plug-in

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Sheriff
Posts: 6968
2
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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();
}
}
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic