Java-to-Javascript communication problem
I'm working on a Java applet that needs to stay in touch with Javascript objects in the web browser. In particular, the applet needs to grab elements from a Javascript array. It turns out that Java to Javascript communication can be done via the
I had everything worked out using the JSObject getSlot method. All went well in Firefox. But then, when I moved over to testing in Internet Explorer (version 6), I got the following error:
Groan. It appears that the
In the applet, the Javascript object and its array are extracted without any problem, using the
netscape.javascript
package, which comes with the Java Plug-in for your browser. I had everything worked out using the JSObject getSlot method. All went well in Firefox. But then, when I moved over to testing in Internet Explorer (version 6), I got the following error:
netscape.javascript.JSException: Unknown name
Groan. It appears that the
getSlot
method is returning this error. I created a very simple test applet and a simple web page with just a single Javascript object that has an array filled with three strings, something like this:
arr[0] = "element 1";
arr[1] = "element 2";
arr[2] = "element 3";
In the applet, the Javascript object and its array are extracted without any problem, using the
getMember
method. Displaying the array in the applet code, I get something like element 1,element 2,element 3
- so the toString method displays the array with commas between the elements. The array is there, correctly filled in. But calling arr.getSlot(int)
in the applet causes the "Unknown name" exception to be thrown. I tried calling getSlot(0)
, getSlot(1)
, and getSlot(2)
- they all throw that exception. So does setSlot
. It's annoying, but I guess I'll have to create a workaround.
0 Comments:
Post a Comment
<< Home