I have a Java Applet in a HTML page. I need to have the applet call a certain Javascript function to notify the HTML page of certain events.
The way I call the JavaScript function currently is:
getAppletContext().showDocument(new URL("javascript:window.notifyEvent("+msisdn+")"));
I define the actual function within the HTML code but when the applet actually calls it I get
the Uncaught ReferenceError: notifyEvent is not defined
error.
Where do I need to define the javascript function for the applet to be able to call it?
Thanks!
Java applets can invoke JavaScript functions present in the same web page as the applet. The LiveConnect Specification describes details about how JavaScript code communicates with Java code.
The Javascript method callApplet () invokes the drawText () method of the applet and passes a time string as an argument. The applet, in turn, updates the label’s text by the string passed from Javascript code. Here is a screenshot of the page: 2. Invoking Java applet’s methods
Java applets can access JavaScript objects, properties, and methods. JavaScript programs can control Netscape plug-ins. You will look at the first capability in this section: accessing Java classes (applets) from within JavaScript.
Calling JavaScript Functions from Java It's also possible to call JavaScript functions, and access JavaScript objects and properties, from within Java. This enables you to use JavaScript's unique capabilities, such as reading the values of form elements, in powerful Java applications.
To do this, you must use JSObject. It's been around for a long time, although I hear there can be differences between browsers still. So if you need to support many browsers I'd suggest checking across your supported set once you see it work in one.
Bridge between the Java applet and the text input controls on the web page
You can give this a try http://docs.oracle.com/javase/tutorial/deployment/applet/invokingJavaScriptFromApplet.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With