ncadge
asked on
Calling Javascript from Java using LiveConnect
I've been struggling with this all day. I want to call a JavaScript function from a java applet, using code that will work in IE4 and Nav 4. LiveConnect should do this. I've followed examples on netscape web site. The following java code below works on IE4 but not on Nav 4. Why?
import netscape.javascript.JSObje ct;
public class Example3 extends Applet {
JSObject win;
/**
* Initialisation section.
*/
public void init() {
// Get a reference to the Navigator Window
try{
win = JSObject.getWindow(this);
}
catch (Exception e){
setBackground(Color.red);
}
Button b = new Button("Say Hello");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEven t e) {
System.out.println("in button click");
sayHello();
}
});
this.add(b);
}
public void sayHello() {
win.eval("alert(\"Hello World\");");
}
public void paint(Graphics g) {
g.drawString("Click the button to say hello", 100, 100);
}
}
import netscape.javascript.JSObje
public class Example3 extends Applet {
JSObject win;
/**
* Initialisation section.
*/
public void init() {
// Get a reference to the Navigator Window
try{
win = JSObject.getWindow(this);
}
catch (Exception e){
setBackground(Color.red);
}
Button b = new Button("Say Hello");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEven
System.out.println("in button click");
sayHello();
}
});
this.add(b);
}
public void sayHello() {
win.eval("alert(\"Hello World\");");
}
public void paint(Graphics g) {
g.drawString("Click the button to say hello", 100, 100);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've tried re-installing Nav.
I have C:\Program Files\Netscape\Communicato