I have been told that the code
<script>
alert(java.lang.System.getProperty("java.version"));
</script>
should alert the java version installed in the browser.
But when I run the code, I get Uncaught ReferenceError: java is not defined.
I tested it in Google Chrome 15, and I am sure that i have java installed. I run a lot of applets daily.
Is the code valid, and if so, what can I do to make it run?
More generally, is it possible to run arbitrary Java code within <script> tags? (Note: I know that Java and JavaScript are different languages.)
You can’t run Java code like that in your script. But there are other ways of getting the Java version. For example looking at the source code of this page, you can see how to list all the browser plugins. You can probably find what you need (ie java version) in all this.