Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Javascript functions from a Java Applet

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!

like image 752
Ben Avatar asked Mar 13 '12 12:03

Ben


People also ask

How do JavaScript functions work with Java applets?

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.

How to use callapplet () method in Java?

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

What can you do with Java applets?

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.

Can you call a JavaScript function from Java?

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.


2 Answers

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

like image 83
sethcall Avatar answered Oct 24 '22 20:10

sethcall


You can give this a try http://docs.oracle.com/javase/tutorial/deployment/applet/invokingJavaScriptFromApplet.html

like image 30
dimcookies Avatar answered Oct 24 '22 22:10

dimcookies