简体   繁体   English

使用JavaScript检测Java版本

[英]Detect version of Java using JavaScript

有没有可靠的方法来检测使用JavaScript在客户端计算机上安装的Java版本?

查看Java Deployment Toolkit中的代码。

According to the fact that we're finding this page with google, just to help the next guys finding this. 根据我们在谷歌找到这个页面的事实,只是为了帮助下一个人找到这个。

Is Java installed? 是Java安装?

navigator.javaEnabled()

http://www.w3schools.com/jsref/met_nav_javaenabled.asp http://www.w3schools.com/jsref/met_nav_javaenabled.asp

Which version of Java is installed? 安装了哪个版本的Java?

<script src="http://www.java.com/js/deployJava.js"></script>
<script>
var versions = deployJava.getJREs();
</script>

http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit

It's the best way I found to find the version of Java with JavaScript, but use it carefully because its version detection is really os/browser dependent, and on old browser version or on recent browser with old Java installed, it'll not work as expected. 这是我发现使用JavaScript找到Java版本的最好方法,但是要小心使用它,因为它的版本检测确实取决于浏览器/浏览器,并且在旧的浏览器版本或最近安装了旧Java的浏览器上,它不会像以前那样工作预期。 Take the time to do real tests before to use it in production. 花时间做真正的测试,然后在生产中使用它。

Googling for 谷歌搜索

detect "java version" using javascript

yields a couple of results, this one looks like it might be useful. 产生了几个结果, 看起来可能有用。 In essence, it tries to load a Java applet and then JavaScript asks the applet. 本质上,它尝试加载Java小程序,然后JavaScript询问小程序。

Version of Java: Java版本:

 /** * @return NULL if not version found. Else return some things like: '1.6.0_31' */ var JavaVersion: function() { var result = null; // Walk through the full list of mime types. for( var i=0,size=navigator.mimeTypes.length; i<size; i++ ) { // The jpi-version is the plug-in version. This is the best // version to use. if( (result = navigator.mimeTypes[i].type.match(/^application\\/x-java-applet;jpi-version=(.*)$/)) !== null ) return result[1]; } return null; } 

Is Java and is Java enable: 是Java并且是Java启用:

 var IsJava: function() { return typeof(navigator.javaEnabled) !== 'undefined' && navigator.javaEnabled(); } 

These functions works on Opera, Firefox, Chrome. 这些功能适用于Opera,Firefox,Chrome。 I havn't IE. 我不是IE。

您可以从这里使用PluginDetect库: http//www.pinlady.net/PluginDetect/

The detection logic does not work in IE32 on Windows7-64. 检测逻辑在Windows7-64上的IE32中不起作用。 It could not detect the java version it installed earlier. 它无法检测到之前安装的java版本。

Well, after further reading, the Java Deployment Toolkit on Windows uses ActiveX classid which may pose your app to hackers (see http://www.kb.cert.org/vuls/id/886582 ). 好吧,在进一步阅读之后,Windows上的Java Deployment Toolkit使用ActiveX classid,这可能会使您的应用程序成为黑客(请参阅http://www.kb.cert.org/vuls/id/886582 )。 I am out. 我出去了。

I find that the JavaScript solution provided by the Java Deployment Toolkit gives an error... "deployJava.do_initialize is not a function". 我发现Java Deployment Toolkit提供的JavaScript解决方案会出错...“deployJava.do_initialize不是函数”。

One solution that I have used extensively for many years that does work in all browsers is the Java Version Display Applet . 我在所有浏览器中广泛使用多年的一个解决方案是Java版本显示小程序 Unfortunately the original author's site seems to have disappeared, but you can download a copy of the Java Version Display Applet here. 不幸的是,原作者的网站似乎已经消失,但您可以在此处下载Java版本显示小程序的副本。

如果您使用Google Analytics, 这篇文章可能会有所帮助(有关详情,请参阅论坛帖子 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM