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("docum ent");
String myCookie = (String) myDocument.getMember("cook ie");
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
public String getCookie()
{
/*
** get all cookies for a document
*/
try
{
JSObject myBrowser = (JSObject) JSObject.getWindow(this);
JSObject myDocument = (JSObject) myBrowser.getMember("docum
String myCookie = (String) myDocument.getMember("cook
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you tried running it with a JApplet, or are you still thinking how to do it?
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.JSExce ption
at netscape.javascript.JSObje ct.getWind ow(Unknown Source.)
Can I not just pass the JApplet in using this, since it is in the scope of the JApplet? Thanks.
JSObject myBrowser = (JSObject) JSObject.getWindow(this);
netscape.javascript.JSExce
at netscape.javascript.JSObje
Can I not just pass the JApplet in using this, since it is in the scope of the JApplet? Thanks.
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.