Current Position:Home > Java and java script communication

Java and java script communication

Update:10-11Source: network consolidation
Advertisement
how to access a javasript string variable in java

The Best Answer

Advertisement
If you are trying to access it from an applet you can do the following:
// call the html page
JSObject win = JSObject.getWindow(this);
JSObject doc = (JSObject) win.getMember("document");
JSObject loc = (JSObject) doc.getMember("location");     
String s = (String) loc.getMember("href");
String stringArg = "status from init()";     
win.setMember("status",stringArg);     
Here win is the JSObject that gets the html page
stringArg is the object value that will be placed into the javascript var.
win.setMember sets the javascript var 'status' with the value placed in stringArg.
You will need to import
import netscape.javascript.*;
also
Mark