471,109 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,109 software developers and data experts.

detect version of java installed?

Does anyone know how to detect the version of Java installed?

My website has an application that requires java 1.5+ to be installed,
basically if the user doesn;t already have it installed I redirect them
to the java download page...

thanks!

Oct 22 '06 #1
4 11292
ao****@hotmail.com wrote:
>Does anyone know how to detect the version of Java installed?

My website has an application that requires java 1.5+ to be installed,
basically if the user doesn;t already have it installed I redirect them
to the java download page...
You're in the wrong group, we discuss Javascript, not Java. The two
are completely different.

Try comp.lang.java.programmer

--
Tim Slattery
Sl********@bls.gov
Oct 23 '06 #2
Tim Slattery wrote:
ao****@hotmail.com wrote:
>Does anyone know how to detect the version of Java installed?

My website has an application that requires java 1.5+ to be
installed, basically if the user doesn;t already have it installed I
redirect them to the java download page...

You're in the wrong group, we discuss Javascript, not Java. The two
are completely different.

Try comp.lang.java.programmer
Not a directly JS related question, I agree, but I have a small applet
that I use in conjuction with JavaScript to determine exactly what the
OP is after...

here's The Applet Code...:

import java.applet.Applet;
import java.awt.HeadlessException;
import java.awt.*;
/**
* @author Dag Sunde
* @version 1.0
*/

public class Detector extends Applet {
public Detector() throws HeadlessException {
}

public void init() {
add(new Label(getJavaVersion()));

}
public String getJavaVersion() {
return System.getProperty("java.version");
}

}
And here's the HTML/JS with how to use it:

<head>
<script type="text/javascript">

var VERSION_REQUIRED = "1.5.0";

function checkPlugIn() {
// Check for Java Plugin Version
var javaVersion;
try {
javaVersion =
document.getElementById('detectPluginApplet').getJ avaVersion();
}
catch (e) {
javaVersion = null;
}

if(javaVersion == null) {
alert("No Java Plugin detected");
}
else {
alert("Java Plugin version " + javaVersion + " detected");
}

if ( javaVersion >= VERSION_REQUIRED ) {
alert("You are cleared to procede...");
}
else {
alert("You must go to the java download page to get the correct Java
Plugin...");
document.location.href =
http://java.sun.com/javase/downloads/index.jsp;
}
return true;
}
</script>
</head>

<body onload="checkPlugIn();">
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
id="detectPluginApplet"
data="Detector.class"
type="application/x-java-applet"
codebase="."
width = "1"
height = "1"
align = "middle"
vspace = "0"
hspace = "0"
>
<param name = "code" value = "Detector"/>
<param name = "codebase" value = ".">
<param name = "mayscript" value ="true"/>
<param name = "scriptable" value = "true">
<param name = "progressbar" value="true" />
<param name = "boxmessage" value="Laster detektor applet"/>
</object>
</body>

--
Dag.
Oct 23 '06 #3
Thanks!

But I tried this, getting the java plugin always results in an error!
(making the javaVersion == null)....


Dag Sunde wrote:
Tim Slattery wrote:
ao****@hotmail.com wrote:
Does anyone know how to detect the version of Java installed?

My website has an application that requires java 1.5+ to be
installed, basically if the user doesn;t already have it installed I
redirect them to the java download page...
You're in the wrong group, we discuss Javascript, not Java. The two
are completely different.

Try comp.lang.java.programmer

Not a directly JS related question, I agree, but I have a small applet
that I use in conjuction with JavaScript to determine exactly what the
OP is after...

here's The Applet Code...:

import java.applet.Applet;
import java.awt.HeadlessException;
import java.awt.*;
/**
* @author Dag Sunde
* @version 1.0
*/

public class Detector extends Applet {
public Detector() throws HeadlessException {
}

public void init() {
add(new Label(getJavaVersion()));

}
public String getJavaVersion() {
return System.getProperty("java.version");
}

}
And here's the HTML/JS with how to use it:

<head>
<script type="text/javascript">

var VERSION_REQUIRED = "1.5.0";

function checkPlugIn() {
// Check for Java Plugin Version
var javaVersion;
try {
javaVersion =
document.getElementById('detectPluginApplet').getJ avaVersion();
}
catch (e) {
javaVersion = null;
}

if(javaVersion == null) {
alert("No Java Plugin detected");
}
else {
alert("Java Plugin version " + javaVersion + " detected");
}

if ( javaVersion >= VERSION_REQUIRED ) {
alert("You are cleared to procede...");
}
else {
alert("You must go to the java download page to get the correct Java
Plugin...");
document.location.href =
http://java.sun.com/javase/downloads/index.jsp;
}
return true;
}
</script>
</head>

<body onload="checkPlugIn();">
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
id="detectPluginApplet"
data="Detector.class"
type="application/x-java-applet"
codebase="."
width = "1"
height = "1"
align = "middle"
vspace = "0"
hspace = "0"
>
<param name = "code" value = "Detector"/>
<param name = "codebase" value = ".">
<param name = "mayscript" value ="true"/>
<param name = "scriptable" value = "true">
<param name = "progressbar" value="true" />
<param name = "boxmessage" value="Laster detektor applet"/>
</object>
</body>

--
Dag.
Oct 26 '06 #4
ao****@hotmail.com wrote:
Thanks!

But I tried this, getting the java plugin always results in an error!
(making the javaVersion == null)....
Ah... Sorry about that... Hadn't tested it myself

It should work in IE (As long as you fixed my typos
and missing string terminators, et.c).

But the object tag won't work properly across browsers,
so replace the html-body i gave you with this instead:

<body onload="checkPlugIn();">
<applet
id="detectPluginApplet"
code="Detector.class"
width = "1"
height = "1"
align = "middle"
vspace = "0"
hspace = "0"
>
</applet>
</body>

and it should work. The "Detector.class" file must of course
be in the same directory as the html-file.

I have now actually tested what I gave you ;-) And it works ok
in IE6.0, FF 2.0 and Opera 9.0...

--
Dag.
Oct 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jan Vinten | last post: by
1 post views Thread by Kevin | last post: by
6 posts views Thread by Fred Hedges | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.