CrossBrowser Java Plugin detection using JavaScript
In this article we will understand how to detect whether the client browser has Java Plugin Installed. This process involves communication between Java and JavaScript.
NOTE:
This tutorial cannot detect the Java Plugin Version installed.
The following steps will guide you to process of detecting Java Plugin on client machine using JavaScript:
- 1. Create Java Applet
Java Applets are used for handshaking purpose as these can be directly embedded inside HTML document using Applet tag. JavaScript will then refer to the applet using the Applet Name, the Applet contains an public function which can be called directly from JavaScript.
1 2 3 4 5 6 7 8 9 | import java.applet.Applet; import java.awt.*; public class checkJava extends Applet { public boolean setMessage() { return true; } } |
Explanation for Java Code:
- Line 1 - Line 5 defines the basic code required for creating an Java Applet
- On Line 6, declared an public function setMessage() that will return an boolean value true
- 2. Writing JavaScript Code:
Next step would be to write an JavaScript code that does the communication with the Java Applet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <html> <body> <applet code="checkJava" width="1" height="1" mayscript="mayscript" name="checkJava"> </applet> <script language="javascript"> try { var x = checkJava.setMessage(); alert(x); } catch(e) { alert("Java Plugin Not Installed"); } </script> </body> </html> |
Explanation for JavaScript Code:
- Here i have placed the java applet inside body tag using applet tag providing with the necessary parameter. Please make sure that mayscript is there inside the applet tag. Without mayscript attribute the handshake will not work
- Applet can be referred inside javascript by the applet name. Referring to Line no 14, calling the setMessage() function by using the Applet Name
- Variable x will hold the value “true” if there was successful communication between JavaScript ans Java Applet
- The try…catch is required to catch the error in case the JavaScript is unable to communicate with Java Applet
- Finally in the catch block i am giving an alert message
Related Post
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.
Comments
Yes, it is possible, but there might be an delay.
See http://www.browserreport.com/ for crossbrowser Java detection.
Hi Hitesh,
checkJava.setMessage();
is not working in Mozilla 3 version
it says that checkJava.setMessage() is not a function
I have used like this












































It may take a while, until the applet loads, but the script is executed immediately. So I don’t believe this is a reliable solution. Sorry.