Running Java code from html -node

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.


I was wrong. :p

What fooled me is that this HTML:

<html> <body> <script type='text/javascript'> if (typeof java === 'undefined') { document.write("Java is not installed."); } else { document.write("java.version " + java.lang.System.getProperty("java.version")); } </script> </body> </html>

..when loaded in <strong>FF</strong> (6.0.1) will produce something like.

java.version 1.6.0_20

Or if loaded in another FF with no Java installed.

Java is not installed.

But just testing it in IE in both situations (Java & no Java) results in:

Java is not installed.

So it only works with 1 out of two of the major browsers (at the moment, as opposed to next month when it might break), and is effectively useless.

Sorry for the misinformation.


Basically what have you been told is not correct.

You're trying to use JavaScript code. JavaScript is not Java (names are bit ambiguous) and you should not miss the difference.

Java is compilable language which can be used in browsers only in form of java applets which could be embedded into a page using Java-plugin (something like Adobe Flash plugin).

JavaScript is a scripting language supported by almost all browsers.

The only common thing between these languages is the title and naming style.


  • Excel - import data from an online xls file daily
  • How does one pull statistics (either daily or over time) from the YouTube API
  • Maven archetype generate with custom properties
  • C# Application Relative Paths
  • Sql indexes vs full table scan
  • Class implementation in a header file == bad style? [duplicate]
  • Flex/AS3 very strange simple Number operation issue
  • Get all existing pointers to an object
  • MySQL multiple IN conditions to subquery with same table
  • Why can't I use non-integral types with switch [duplicate]
  • Is it possible to get the word under the mouse cursor in a ``?
  • Javascript/Jquery runs fast in desktop browsers, but slow in mobile/smartphone browsers…should I spl
  • Jenkins Grails plugin does not list lastest versions of Grails
  • BeautifulSoup difference between findAll and findChildren
  • NHibernate manually control fetching
  • Use tryCatch within R loop
  • Access user's phone number on iOS 7
  • Tamper-proof configuration files in .NET?
  • Unable to decode certificate at client new X509Certificate2()
  • Nant, Vault & Windows Integrated Authentication
  • Counter field in MS Access, how to generate?
  • HTML download movie download link
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Updating server-side rendering client-side
  • Cross-Platform Protobuf Serialization
  • Validaiting emails with Net.Mail MailAddress
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Javascript + PHP Encryption with pidCrypt
  • Release, debug version and Authorization Google?
  • Websockets service method fails during R startup
  • WOWZA + RTMP + HTML5 Playback?
  • Is there a mandatory requirement to switch app.yaml?
  • How to format a variable of double type
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How to set the response of a form post action to a iframe source?
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • How does Linux kernel interrupt the application?
  • JaxB to read class hierarchy