Link to home
Start Free TrialLog in
Avatar of ncadge
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.JSObject;
 
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(ActionEvent 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);
      }
}
Avatar of ncadge
ncadge

ASKER

ps.

I've tried re-installing Nav.

I have C:\Program Files\Netscape\Communicator\Program\Java\Classes\java40.jar in my CLASSPATH.

ASKER CERTIFIED SOLUTION
Avatar of TomWilson
TomWilson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial