Solved

find JRE version

Posted on 2006-06-09
17
2,805 Views
Last Modified: 2008-01-09
how can i find and display the JRE version installed on machine?
0
Comment
Question by:ellandrd
  • 8
  • 4
  • 3
  • +1
17 Comments
 
LVL 10

Accepted Solution

by:
0h4crying0utloud earned 500 total points
Comment Utility


This is how I do it:

alert("JRE Version: " + document.myApplet.getJavaVersion());

Here's more info:
HOW TO DETECT Java Plugin from JavaScript:
http://forum.java.sun.com/thread.jspa?threadID=168544&start=0
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
of course, the javascript will not work until the applet has fully loaded...
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
see i dont think this will work for me.

ive got webpage X that uses an applet and redirects to webpage Y.

but what ive found is that webpage X wont work (applet dont get loaded webpage X hangs) unless the user has an JRE installed, hence why i want to check for an JRE first but trying to load & start applet.
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
>>hence why i want to check for an JRE first but trying to load & start applet.

should read

hence why i want to check for an JRE first before trying to load & start applet.
0
 
LVL 10

Expert Comment

by:0h4crying0utloud
Comment Utility

Here's an excerpt from one of the comments in the sun developer forum: Note the IE stipulation


Try following java script, it works on new browsers (NS 4+, IE5+). For IE you have to enable 'ActiveX objects creation' in security options.


var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);


var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav4up = (is_nav && (is_major >= 4));

var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.0") !=-1));
var is_ie5up = (is_ie && (is_major == 4)
&& ( (agt.indexOf("msie 5.0")!=-1)
|| (agt.indexOf("msie 5.5")!=-1)
|| (agt.indexOf("msie 6.0")!=-1) ) );

var pluginDetected = false;
var activeXDisabled = false;

// we can check for plugin existence only when browser is 'is_ie5up' or 'is_nav4up'
if(is_nav4up) {
// Refresh 'navigator.plugins' to get newly installed plugins.
// Use 'navigator.plugins.refresh(false)' to refresh plugins
// without refreshing open documents (browser windows)
if(navigator.plugins) {
navigator.plugins.refresh(false);
}

// check for Java plugin in installed plugins
if(navigator.mimeTypes) {
for (i=0; i < navigator.mimeTypes.length; i++) {
if( (navigator.mimeTypes[ i].type != null)
&& (navigator.mimeTypes[ i].type.indexOf(
"application/x-java-applet;jpi-version=1.3") != -1) ) {
pluginDetected = true;
break;
}

}
}
} else if (is_ie5up) {
var javaVersion;
var shell;
try {
// Create WSH(WindowsScriptHost) shell, available on Windows only
shell = new ActiveXObject("WScript.Shell");

if (shell != null) {
// Read JRE version from Window Registry
try {
javaVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\CurrentVersion");
} catch(e) {
// handle exceptions raised by 'shell.regRead(...)' here
// so that the outer try-catch block would receive only
// exceptions raised by 'shell = new ActiveXObject(...)'
}
}
} catch(e) {
// Creating ActiveX controls thru script is disabled
// in InternetExplorer security options

// To enable it:
// a. Go to the 'Tools --> Internet Options' menu
// b. Select the 'Security' tab
// c. Select zone (Internet/Intranet)
// d. Click the 'Custom Level..' button which will display the
// 'Security Settings' window.
// e. Enable the option 'Initialize and script ActiveX controls
// not marked as safe'

activeXDisabled = true;
}

// Check whether we got required (1.3+) Java Plugin
if ( (javaVersion != null) && (javaVersion.indexOf("1.3") != -1) ) {
pluginDetected = true;
}
}


if (pluginDetected) {
// show applet page
} else if (confirm("Java Plugin 1.3+ not found, Do you want to download it?")) {
// show install page
} else {
// show error page
}
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
Ok half working...

i use 1.5.0_07 and im forcing all users to be the same...

my reg key is:

HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.5.0_07


i have tried this but dont work:

javaVersion = (shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.5.0_07")) ? "1.5.0_07" : "1.3" ;


                  
                  
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
why 1.5.0_07?

Surely just "1.5.0" or better would do?

Forcing people to use a particular update of a particular version seems a little restrictive (and harsh)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Why not

 javaVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\CurrentVersion");
if (javaVersion !='1.5.0_07') { alert('Nope'); javaVersion='1.3'; }
else ...
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Author Comment

by:ellandrd
Comment Utility
because i dont have a folder called "CurrentVersion" in my registry...

after HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\

i have a folder "1.5" & another folder "1.5.0_07"
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
sorry tim didnt see your post.

ya 1.5 would do... i wasnt thinking while i typed a reply....
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
ok the script isnt even getting to that point.

ive insertted some debugging statements and the script stops right before:

document.writeln("here");

// we can check for plugin existence only when browser is 'is_ie5up' or 'is_nav4up'
if(is_nav4up)
{
   ...

on my page, the only statement i see is "here"...

im actually testing this on IE7, but my users use IE5+
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
ok, i tested it in IE5+ and it now fails here:

// Create WSH(WindowsScriptHost) shell, available on Windows only
shell = new ActiveXObject("WScript.Shell");



any idea's?
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
OK, i cannot get script to work as the security build into IE7 wont allow webpage to be run with initialize and script ActiveX controls enabled, but IE5+ will so i now have want i want working...

just let me give it a few more tests before i accept...

ellandrd
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
How do you get


alert("JRE Version: " + document.myApplet.getJavaVersion());

to work????

I get Object does not support....

<HTML>
<Head>
<Title> A Simple Program </Title>
<script>
function showStuff() {
showIt=true
  var x = document.getElementById('app');
  txt = "";
  try {
    txt += 'version:'+x.getJavaVersion()

    for (i in x) {
      txt +='<hr>'+i
      if (i!='outerHTML') txt +=':<br>'+((x[i])?x[i]:'not set')
     }
     txt+='<hr>'
  }
  catch(e) { alert(e.message)}
  document.getElementById('resu').innerHTML=txt;
}
</script>
<Body onLoad="showStuff()">
<Applet id="app" Code="HelloWorld.class" width="150" height="50"></Applet>
<div id="resu"></div>

</Body>
</HTML>

0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
You can't call it onload

You have to call it after the applet is loaded (via a link or timer or something)

I *think* that's the problem...
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Nope

<HTML>
<Head>
<Title> A Simple Program </Title>
<script>
function showStuff() {
showIt=true
  var x = document.getElementById('app');
  txt = "";
  try {
    txt += 'version:'+x.getJavaVersion()

    for (i in x) {
      txt +='<hr>'+i
      if (i!='outerHTML') txt +=':<br>'+((x[i])?x[i]:'not set')
     }
     txt+='<hr>'
  }
  catch(e) { alert(e.message)}
  document.getElementById('resu').innerHTML=txt;
}
</script>
<body onLoad="setTimeout('showStuff()',2000)">
<Applet id="app" Code="HelloWorld.class" width="150" height="50"></Applet>
<div id="resu"></div>

</Body>
</HTML>
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
<Applet id="app" Code="HelloWorld.class" width="150" height="50" MAYSCRIPT></Applet>

?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now