Solved

Auto Detect and Install Java VM

Posted on 2004-03-26
5
691 Views
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.  

Thanks!
0
Comment
Question by:brianrandy
  • 3
5 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 125 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:

<html>
<head>
<title>Title</title>
<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);
   newWin.focus();
   return true;  }
}
// -->
</script>
</head>
<body onload="check_java();">
Content
</body>
</html>

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 :)

0
 
LVL 36

Expert Comment

by:Zyloch
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:

...ubar=yes,copyhistory=yes,resizable=yes,width='...

The resizable allows the browser to be resized.

I hope this supplementary post helps.

0
 
LVL 36

Expert Comment

by:Zyloch
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.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

776 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