Link to home
Start Free TrialLog in
Avatar of wojsoft
wojsoft

asked on

LiveConnect

My problem concern on communication between JavaScript and Java in Netscape Navigator or Communicator.
In the LiveConnect documentation has been written:
      "Before you can access JavaScript, you must get a handle for the Navigator window. Use the getWindow method
in the class netscape.javascript.JSObject to get a window
handle, passing it the Applet object."
I need derive from JS some information about connection
(location.port, location.host),but I have no applet,
only Java object created in JS:
<script>
navigator.myobject =Packages.JSTest();
</script>
thus I cannot call like inside applet:
      JSObject win = JSObject.getWindow(this);
How can I access JavaScript objects and its properties???.
Is it possible?.
Avatar of rembo
rembo

Here's an example of how to access the JavaScript from
Java:

      JSObject win = null;
        JSObject doc = null;

        if (url == null)
            return;

        try {
            win = JSObject.getWindow(parent);

                    win.eval(url + ";");
        } catch (Exception e) {
            System.out.println("JavaScript error msg: " + e.getMessage());
           
        }
      
If you want to access generic JavaScript objects from there,
just do the eval of the command you want to execute on that
page.  You can also access Java from JavaScript, but I'm
a little uncluear on what your actual question is.

-Tony

Avatar of wojsoft

ASKER

What is this parent parameter?
Function getWindow() is defined like below:
public static JSObject getWindow(Applet applet)
ASKER CERTIFIED SOLUTION
Avatar of rembo
rembo

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