Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript to Java communication using LiveConnect not working
    text
    copied!<p>I've been working on a project that requires communication both directions between Java and JavaScript. I have successfully managed to get it working under all browsers in OS X, but I'm now faced with the challenge of getting it to run on Windows under any browser. At the moment it simply doesn't work.</p> <p>I'm just wondering if there is something special I need to do in order for JavaScript to communicate with Java? </p> <p>My applet code looks like this:</p> <pre><code>&lt;applet id='theApplet' code="com/company/MyApplet.class" archive="SMyApplet.jar" height="50" width="900" mayscript="true" scriptable="yes"&gt; Your browser is ignoring the applet tag. &lt;/applet&gt; </code></pre> <p>Once the applet has loaded, I then try to call functions on it like this:</p> <pre><code> alert("Call some java:" + theApplet.testFunc()); </code></pre> <p>And in the firebug console I get the following error:</p> <pre><code>theApplet.testFunc is not a function </code></pre> <p>I can confirm that this doesn't work in IE either.</p> <p>When the page loads, I have the java console open and I can see that the applet is successfully loading and ready to accept calls.</p> <p>Any help would be greatly appreciated!</p> <p>Cheers</p> <hr> <p>Update: Here is the stripped down java code exposing the public api that I'm trying to call.</p> <pre><code>package com.company; import com.google.gson.Gson; import java.applet.*; import java.io.*; import java.net.*; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.*; import javax.xml.namespace.QName; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.*; import netscape.javascript.*; public class MyApplet extends Applet implements Runnable { public void init() { JSON = new Gson(); isReadyVar = 0; workThread = null; } public void start() { } public void run() { System.out.println("Done"); } public void stop() { } public void destroy() { } /* Public API */ public int testFunc() { return 200; } } </code></pre> <hr> <p>Update [SOLVED]:</p> <p>I figured out what the problem was exactly. Turns out the Gson lib I was using wasn't signed; but my own jar was. Browsers on windows require that all libs are signed; so I packaged Gson in with my java files &amp; signed the lot and it solved the problem! Thanks for everyones help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload