| Author |
Returning array from applet to JavaScript
|
Terry Sessford
Greenhorn
Joined: Sep 27, 2005
Posts: 2
|
|
Hi, I have a question for which I cannot find an answer and would be very grateful for some help. I have a Java applet within an HTML page and I can call the applet's methods from JavaScript without a problem when the page is viewed in Internet Explorer 6.0. If an applet method returns any Java primitive data type then the value can be assigned to a JavaScript variable and displayed (and this is also true if the applet method returns a Java String). However, if an applet method returns a Java array then the JavaScript variable to which it is assigned is always valueless. So, with Internet Explorer 6.0 is it actually possible to have an applet method that returns a Java array to JavaScript? If so, could someone please provide a simple example. Many thanks. Terry.
|
 |
Norm Radder
Ranch Hand
Joined: Aug 10, 2005
Posts: 681
|
|
|
Return your array as a character delimited String. Chose a delimiter that won't appear in the data. Then write a routine in Javascript to parse it and return it to an array. To speed it up, pass the number of elements as the first part of the string.
|
 |
Todd Jaspers
Greenhorn
Joined: Aug 29, 2005
Posts: 23
|
|
I've done this kind of thing with other languages as well.. for example, passing an array as a comma delimeted string from a DLL to a VB scripting language. This idea works pretty well...
|
 |
Terry Sessford
Greenhorn
Joined: Sep 27, 2005
Posts: 2
|
|
Thank you both for your suggestions. I had considered this approach but was hoping to avoid conversion to a string because one of the arrays I wish to return to JavaScript from the Applet is a byte array which I then wish to pass to an ActiveX method which will accept the byte array as a variant data type. Thus ideally I would like the JavaScript to accept the Java byte array as a sort of 'blob', the contents of which I do not not need to access in the JavaScript itself. Terry.
|
 |
 |
|
|
subject: Returning array from applet to JavaScript
|
|
|