Auto Detect and Install Java VM

Posted on 2004-03-26
Medium Priority
Last Modified: 2012-08-14
I need to auto detect for the latest version of java (or java vm or jre) so that users can run an applet.  If java is not enabled, installed or running it should open the java.com page in a new window that will then install the latest version of java.

I just need the exact code required to do this.  I have read about using the object tag and some other ideas but the exact code for html is what I need.  Also, this code should work on all browsers and OS.  I am sure this has been done before but I having trouble finding the exact answer.  

Question by:brianrandy
  • 3
LVL 36

Accepted Solution

Zyloch earned 500 total points
ID: 10845988
I am not sure if you can detect the LATEST version of Java. However, it is possible to check to see if Java is enabled with a little bit of JavaScript.

In the body or head of your document, you can include this script:

<script language="JavaScript">
<!--Hide from older browsers
function check_java() {
  if (navigator.javaEnabled()) {
    return true;
  else {
    var width=screen.width;
    var height=screen.height;
    newWin = window.open('http://java.sun.com/j2se/1.4.2/download.html','newWind', 'toolbar=yes,location=yes,scrollbars=yes,directories=yes,status=yes,menubar=yes,copyhistory=yes,width='+width+',height='+height);
   return true;  }
// -->
<body onload="check_java();">

This is a short example of the best you can do with HTML and JavaScript alone.

This script using the onLoad event handler, as soon as the site loads, does the check_java() function.
check_java performs a check to see if Java is enabled. If it is, it returns true and does nothing. If Java isn't enabled, it will open to the download page. Please provide instructions to download the Java JRE as it is not possible to directly link to the download page because of session IDs (you can alert them in an alert box possibly or another popup)

The other way to do this is to upload the newest Java JRE to another site of your own so you can directly link to the file and start download immediately. However, the downside to that method is that it may be illegal. Also, some people may just have Java disabled and don't need to download the installation file.

Hope this helps :)

LVL 36

Expert Comment

ID: 10846018
Also, one more thing. I noticed that above, I typed:

var width=screen.width;
var height=screen.height;

You may wish to change it to:

var width=screen.width;
var height=screen.height-40;

Otherwise, the browser may obscure the Start Menu.

Another change you MAY want to change is where I typed:

newWin = window.open('http://java.sun.com/j2se/1.4.2/download.html','newWind', 'toolbar=yes,location=yes,scrollbars=yes,directories=yes,status=yes,menubar=yes,copyhistory=yes,width='+width+',height='+height);

You may wish to add this to right after copyhistory=yes:


The resizable allows the browser to be resized.

I hope this supplementary post helps.

LVL 36

Expert Comment

ID: 10846055
Finally, I would like to point out a problem with the above method:

If your users have a popup blocker, you may have to also warn them on the page to disable it.

Mozilla Firefox v0.8, I know for a fact, suppresses popups automatically. To stop that, tell your Mozilla Firefox visitors to go to

Tools -> Options
Click on Web Features in Menu at left.
Uncheck the Block Popups checkbox.
Click Ok.

The above script has been tested in Netscape, Internet Explorer, Mozilla Firefox, and Opera. All seem to work fine.

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question