Entry
How to determine with JavaScript if Java is enabled in a browser?
Nov 23rd, 2002 04:50
Martin Honnen, Jean-Bernard Valentaten, Paco Calvo,
The
window.navigator
object has a method
window.navigator.javaEnabled
that you can call where it is supported (at least NN4, NN6, NN7, Opera
6, Opera 7, IE4+).
Browsers that support Liveconnect (like NN4, NN7, Opera 7)
additionally allow you to check for the Java version by calling into
Java (note that this starts the Java virtual machine):
<html>
<head>
<title>
Java version test
</title>
<script type="text/javascript">
function checkJavaSupport () {
var result = {
javaEnabled: false,
version: ''
};
if (typeof navigator != 'undefined' && typeof navigator.javaEnabled !
= 'undefined')
result.javaEnabled = navigator.javaEnabled();
else
result.javaEnabled = 'unknown';
if (navigator.javaEnabled() && typeof java != 'undefined')
result.version = java.lang.System.getProperty("java.version");
return result;
}
</script>
</head>
<body>
<p>
Checking for Java support:
<br />
<script type="text/javascript">
var javaCheck = checkJavaSupport();
document.write('Java enabled/supported: ' + javaCheck.javaEnabled
+ '<br />');
document.write('Java version: ' + javaCheck.version);
</script>
</p>
</body>
</html>