Link to home
Start Free TrialLog in
Avatar of kesea
kesea

asked on

Getting a Broswer Cookie from a JApplet

Hi there, well I seem to be having some trouble retrieving a cookie from a JApplet.  The code I have works fine in an Applet, but not a JApplet.  I am just trying to get a cookie from the browser called "Session".  I was using this:

  public String getCookie()
  {
     /*
      ** get all cookies for a document
      */
     try
     {
        JSObject myBrowser = (JSObject) JSObject.getWindow(this);
        JSObject myDocument = (JSObject) myBrowser.getMember("document");
        String myCookie = (String) myDocument.getMember("cookie");
        if (myCookie.length() > 0)
           return myCookie;
     }
     catch (Exception e)
     {
        e.printStackTrace();
     }
     return "?";
  }

But the JSObject.getWindow takes in an Applet.  Any suggestions?  Thanks in advance.

Kes
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

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
Have you tried running it with a JApplet, or are you still thinking how to do it?
Avatar of kesea
kesea

ASKER

I have tried it from an Applet and a JApplet, but with my JApplet I get this exception from the

JSObject myBrowser = (JSObject) JSObject.getWindow(this);  

netscape.javascript.JSException
      at netscape.javascript.JSObject.getWindow(Unknown Source.)

Can I not just pass the JApplet in using this, since it is in the scope of the JApplet?  Thanks.
Avatar of kesea

ASKER

Ok I figured it out.  You cannot call this function from the JInit or else it will fail.  I guess the browser hasn't loaded the JApplet fully by then.  Thanks all for the sanity check.