Results 1 to 2 of 2
  1. #1
    silvia is offline Member
    Join Date
    Jul 2007
    Posts
    35
    Rep Power
    0

    Default Help with JSobject from the netscapte

    Hi, I am workig in a project on javascript. For which i need java and javascript communication.
    I am working with JSobject from the netscapte and i am getting worked in one way.
    When i am invoking the applet thru webpage i am getting the applet methods working with javascript and when i try to acess the javascript or object for getting the webpage contents i am getting the jsexception

    here is the applet code i am using
    Java Code:
    import netscape.javascript.*;
    import java.applet.*;
    import java.awt.*;
    
    public class MyApplet extends Applet {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    
    public void init() {
    JSObject win = JSObject.getWindow(this);
    JSObject doc = (JSObject) win.getMember("document");
    JSObject loc = (JSObject) doc.getMember("location");
    
    win.call("f", null); // Call f() in HTML page
    }
    
    public void wish()
    {
    JSObject win = JSObject.getWindow(this);
    JSObject doc = (JSObject) win.getMember("document");
    JSObject loc = (JSObject) doc.getMember("location");
    
    Object[] args ={ "hello from java"};
    win.call("doit",args);
    }
    
    }
    Here is the code in html page thru which i am invoking the applet
    Java Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <applet id="Calculator" width="300" height="500" code="MyApplet.class" codebase="." MAYSCRIPT>
    <param name="InitialMode" value="Normal">
    </applet>
    <HTML>
    <SCRIPT language="JavaScript">
    function f()
    {
    alert("hello world");
    }
    function doit(msg)
    {
    alert("entered do it ");
    //var msg = document.Calculator.wish;
    alert(msg);
    }
    function startJSFractal()
    {
    document.calculator.init();
    }
    </SCRIPT>
    
    <BODY>
    <form name="Form1">
    <!--<OBJECT ID="Fractal" WIDTH=500 HEIGHT=120
    CLASSID="CLSID:8AD9C840-044E-11d1-B3E9-00805F499D93"
    <PARAM NAME="code" value="MyApplet.class">
    <PARAM NAME="codebase" value="1.0.2">
    <PARAM NAME="level" value="5">
    </OBJECT>-->
    <input type="button" name="Button1" value="Start"
    onClick="document.Calculator.wish()" language="JavaScript">
    
    </BODY>
    </HTML>
    so when i try to run the applet i am getting the jsexception , but its working with the html page
    Java Code:
    netscape.javascript.JSException
    at netscape.javascript.JSObject.getWindow(JSObject.java:144)
    at MyApplet.init(MyApplet.java:14)
    at sun.applet.AppletPanel.run(AppletPanel.java:378)
    at java.lang.Thread.run(Thread.java:595)
    Thanks

  2. #2
    barney is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    After all at it's very beginning (LiveScript was it's maiden name, if I remember well) javascript developed by Netscape supposed exactly to make a communication "bus" between the client-side state and the Java language/applets (the moment Netscape decided to have a partnership with Sun).
    Greetings.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •