可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have an ASP .NET website that hosts a Java applet. The Java applet requires version 1.6 Update 11 of the Java runtime.
How can I detect that a client has the appropriate runtime installed so that I can display an informative message if they do not?
Thanks,
Carl.
EDIT: The solution must be platform independant.
回答1:
This page describes how to and lists some plugins that will allow you to detect Java with JavaScript: http://www.pinlady.net/PluginDetect/JavaDetect.htm
Other than that, try out this snippet as well:
if (navigator.javaEnabled()) {
//Java is enabled
}
回答2:
The link below details on the deployment tips for java apps.
http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html
Quoting from the link
Deployment Toolkit
To avoid browser compatibility issues, the Deployment Toolkit (deployJava.js) provides JavaScript functions that automatically generate HTML required to deploy applets and Java Web Start applications. Developers should invoke these functions to deploy their solutions in a consistent fashion across various browsers.
回答3:
My approach would be to use the JavaScript navigator.javaEnabled()
to check if there is some Java version available.
Then you can use System.getProperty("java.version")
from within a Java applet itself. That should be enough to get you the version information, such as 1.6.0_03
.
回答4:
Although most of the answers so far are all around detection on the user agent (browser) itself, it sounds like from your mention of ASP.NET that you'd like to make this detection happen on the server-side. If so, you have a couple of options.
First you can sniff the HTTP request headers coming from the user agent. A computer and browser with Java installed will usually include a header providing a hint of this to the server that you can pick up on. Here are some useful links on this approach:
http://www.developershome.com/wap/detection/
https://metacpan.org/pod/HTTP::Browscap
The other option you have is to send down javascript to the user agent to perform the detection using one of the techniques in the other answers in this question and then use ajax callbacks to tell the server what you discovered.
回答5:
If you don't mind using a basic java applet that requires a much older version to run, you could use this article and continue based on that result.
回答6:
Maybe this script will help. This is Windows-only, though.
<script language='javascript' type='text/javascript'>
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\\");
}
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(...)'
alert('error reading registry');
}
}
}
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.6) Java Plugin
if ( javaVersion != null && javaVersion.indexOf("1.6"))
{
pluginDetected = true;
alert('it is installed!')
}
if (pluginDetected)
{
// show applet page
}
else if (confirm("Java Plugin 1.6 not found"))
{
// show install page
alert('not found')
}
else
{
// show error page
alet('error')
}
</script>
回答7:
If the solution must be platform independent. I'll exclude all solution provided by javascript.
You can write a very simple Applet which support by the oldish Classic VM. Let the applet detect the JRE version, and display messsage.
If you accept Javascript, you may also interest to this article which is about auto-installer for WebStart applications.
回答8:
Use deployJava.js function getJREs() to build a dynamic page depending on the user's Java version.
Use http://cowwoc.blogspot.com/2008/12/tracking-java-versions-using-google.html to track the Java version being used by your web visitors using Google Analytics.
Bonus step: use the source-code from step 2 as an example of how step 1 should be implemented.
回答9:
Just copy amd paste this code in your browser address bar!
Check if it is useful for you.
javascript: for(i = 0; i < navigator.plugins.length; i++) alert(navigator.plugins[i].name);
You need to obtain the position of Java in the plugins array and maybe you can check the versions with a regular expression or something. You could take a look to the plugin javascript object.
Regards!
回答10:
check this
http://simple-java-detection-script.blogspot.com/2010/03/simple-browser-java-installed-or.html
回答11:
The link below was the way I got it to work. It has a JS you can get which was made for Java deployment. The link was mentioned above, but I thought an example with it would be nice.
These are samples that I ended up needing to fix my problem.
http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit
Once you have downloaded the deployJava.js file you could put something to make sure java is installed:
if (deployJava.getJREs().length > 0) {
//Your code to start java
}
Make sure a specific version is installed:
if (deployJava.versionCheck(version)) {
//Your version specific code
}
Start the installer of the latest Java:
deployJava.installLatestJava();
Or a specific version if you would like:
deployJava.installJRE(version);
回答12:
Copy and paste into your browser address bar to check:
javascript:alert(navigator.javaEnabled())
Works in Mozilla (FF3) and IE7. (x64)