javascript来检测客户端java版本

时间:2015-04-23 07:49:03

标签: javascript

我正在尝试使用 deployJava 来获取客户端java版本。但let setting:[[Int]] = [ [0,0,0,0,0,0,2230], [0,0,0,0,0,2230,2157], [0,0,0,0,2230,2230,2085], [0,0,0,0,2230,2226,2017], [0,0,0,2230,2230,2222,1949], [0,0,2230,2230,2230,2218,1880], [0,0,2230,2230,2230,2135,1807], [0,2230,2230,2230,2230,2052,1735], [0,2230,2230,2230,2163,1965,1655], [2230,2230,2230,2230,2096,1878,1576], [2230,2230,2230,2191,2022,1793,1497], [2230,2230,2230,2096,1909,1708,1415], [2230,2230,2171,2003,1818,1623,1337], [2230,2230,2112,1910,1728,1539,1259], [2197,2214,2021,1820,1639,1454,1195], [2164,2199,1930,1731,1551,1370,1131], [2066,2104,1842,1645,1465,1302,1067], [1969,2010,1755,1559,1380,1234,1003], [1884,1902,1650,1460,1294,1155,0], [1799,1794,1546,1362,1209,1077,0], [1726,1665,1429,1259,1110,0,0], [1654,1537,1312,1157,1012,0,0], [1579,1422,1211,1059,0,0,0], [1505,1308,1111,961,0,0,0] ] 返回空值。我使用的是Windows 7-64bit 有没有办法检测客户端java版本?

1 个答案:

答案 0 :(得分:0)

首先,您需要使用以下代码片段验证是否在客户端计算机上启用了Java

navigator.javaEnabled()

如果它返回true表示启用了java,现在进一步在代码片段下面

Java版本:

  /**
   * @return NULL if not version found. Else return some things like: '1.6.0_31'
   */
 var JavaVersion: function()
 {
    var resutl = 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( (resutl = navigator.mimeTypes[i].type.match(/^application\/x-java-applet;jpi-version=(.*)$/)) !== null )
            return resutl[1];
    }
    return null;
  }

或者您可以使用javascript

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