【问题标题】:Detect java version using deployJava.js ,pops up java upgrade menu使用deployJava.js检测java版本,弹出java升级菜单
【发布时间】:2014-01-06 05:22:45
【问题描述】:

我需要知道客户端机器上安装的java版本,在这里想出了解决方案

How to write JavaScript function to check JRE version

当我尝试时,得到了答案:

console.log(deployJava.getJREs());

但是在地址栏,弹出菜单是这样显示的

如何隐藏?

如果这不能实现,请提出任何其他的想法来实现,因为这个不能使用,如果这个弹出没有被抑制

【问题讨论】:

    标签: java javascript deployjava


    【解决方案1】:

    从最近的实验中我很确定没有办法抑制它。对于检测插件版本的脚本,它必须调用插件本身。


    在这些实验之后,我创建了一个脚本,该脚本可以在不调用插件本身的情况下检测出关于 Java 插件的各种事情。他们依靠检查 mime 类型信息。

    这仍然会在 IE 中显示警告如果从本地文件系统打开。但我希望如果从 Internet 加载它会更宽容。请回来报告。

    但请注意,当“允许脚本”检查正常时,它为 IE 报告的内容。

    HTML

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Java Information - Non Deployment Toolkit Script</title>
    <meta name='author' content='Andrew Thompson'>
    <meta name='description' content='Non Deployment Toolkit Script'>
    <script src='mimetypes.js'></script>
    <style type='text/css'>
    .true {
        background-color: #6F6;
    }
    .false {
        background-color: #FB0;
    }
    .undefined {
        background-color: #FF0;
    }
    .datum {
        font-family: monospace;
    }
    
    td {
        padding: 4px;
    }
    </style>
    </head>
    <body>
    
    <h1>Java on this PC</h1>
    
    <h2>Overview</h2>
    <p>This page endeavors to ascertain the installation, availability
    &amp; version of the Java installed on the client PC.
    More importantly, it attempts to discover the information <b>without
    invoking the Java Plug-In</b> itself.
    The last part is what makes it different
    to the Deployment Toolkit Script supplied by Oracle.
    </p>
    
    <script type='text/javascript'>
    
    document.write("<h2>Browser Info.</h2>");
    document.write(getBrowserInfo());
    
    
    document.write("<h2>Basic Info.</h2>");
    document.write("<table border='1'>");
    
    document.write(get3CellRow('<b>Enabled</b>', isJava(), 'Java is enabled (1.1+) - IE info. (short of ActiveX) stops here'));
    document.write(get3CellRow('<b>Version</b>', getVersion(), 'Maximum version reliably <em>known</em> to be available'));
    if (isIE()) {
        document.write(get3CellRow('<b>MSIE</b>', getIEVersion(), 'Maximum version reliably known to be available in IE, tested using ActiveX'));
    }
    document.write(get3CellRow('<b>JWS</b>', isJWS(), 'Java Web Start available (1.4.2+)'));
    document.write(get3CellRow('<b>Plug-In 2</b>', isPlugin2(), 'Plug-In 2 available (1.6.0_10+)'));
    
    document.write("</table>");
    
    if (plugins.length>0) {
        document.write("<h2>Navigator Plug-Ins</h2>");
        document.write("<table border='1'>");
        document.write("<tr><th>Name</th><th>Version</th><th>File Name</th><th>Description</th></tr>");
        for (var ii=0; ii<plugins.length; ii++) {
            var t = plugins[ii].name;
            if (t.indexOf("Java")>-1) {
                document.write("<tr>");
                document.write("<td>" + plugins[ii].name + "</td>");
                document.write(getDataStyledCell(plugins[ii].version));
                document.write("<td>" + plugins[ii].filename + "</td>");
                document.write("<td>" + plugins[ii].description + "</td>");
                document.write("</tr>");
            }
        }
        document.write("</table>");
    }
    
    if (mimes.length>0) {
        document.write("<h2>Navigator Mime-Types</h2>");
        document.write("<table border='1'>");
        document.write("<tr><th>Mime</th><th>Description</th><th>Types</th></tr>");
        for (var ii=0; ii<mimes.length; ii++) {
            var t = mimes[ii].type;
            if (t.indexOf("java")>0 &&
                ((t.indexOf("jpi")>0 || t.indexOf("deploy")>0 || t.indexOf("jnlp")>0 || t.indexOf("vm")>0) ||
                mimes[ii].description.length>0)
                ) {
                document.write("<tr>");
                document.write("<td>" + mimes[ii].type + "</td>");
                document.write("<td>" + mimes[ii].description + "</td>");
                document.write("<td>" + mimes[ii].suffixes + "</td>");
                document.write("</tr>");
            }
        }
        document.write("</table>");
    }
    </script>
    
    <hr>
    
    <h2>Description</h2>
    <p>In order (if available) the information is:
    
    <ul>
    <li><b>Browser info. Table:</b>  Not strictly related to Java - the
    information in the other tables is determined without
    further reference to any information shown in this table (except for the <code>appName</code> used for
    identifying IE).
    OTOH it is an helpful guide
    as to what we should be <em>expecting</em>
    from the other information. E.G.  IE
    will not show the Plug-In or Mime Type tables.  <em>Only</em>
    FF displays the plug-in version numbers.
    </li>
    <li><b>Basic info. Table</b>
        <ul>
        <li><b>Enabled</b>:  Java is known to this browser and enabled, according to JavaScript <code>navigator.javaEnabled()</code>.</li>
        <li><b>Version</b>:  The maximum Java version known to be supported in this browser/PC.
        It is set to <code>1.1</code> if the previous check is <code>true</code>, since the MSVM
        was the first Java version the public could get in a browser, and the MSVM
        implemented Java 1.1.  Goes on to check
        <code>application/x-java-applet;jpi-version</code>
        in the mime types if available
        (i.e. typically browsers that are <em>not</em> IE).
        </li>
        <li><b>MSIE</b> (IE Only):  The maximum Java version known to be supported by this instance of Internet Explorer
        as determined using ActiveX.  It runs from 1.4.2, 1.5.0.. through 1.9.0.
        </li>
        <li><b>JWS</b>:
        Inferred from a comparison of the version to the Sun JRE in which
        it was co-bundled.</li>
        <li><b>Plug-In 2</b>:
        Inferred from a comparison of the version to the Sun JRE in which
        it was introduced.</li>
        </ul>
    </li>
    <li><b>Navigator Object Tables:</b>
        <em>The rest of the info. is gleaned from the <code>navigator</code> object.
        IE does not include this information.</em>
        <ul>
        <li><b>Plug-Ins</b>: More details of the Java related plugins.
        Filtered for <code>Java</code> in the <code>name</code>.
        A <code>description</code> showing "Next Generation Java Plug-in" or <code>name</code>
        "Java Deployment Toolkit" should be 1.6.0_10+.</li>
        <li><b>Mime-Types</b>: More information on the Java related Mime-Types.
        Filtered in <code>mime</code> field for <code>'java'</code> + <code>('jpi'||'vm'||'deploy')</code>
        or a non-empty <code>description</code>.
        The value <code>java-deployment-toolkit</code> in the <code>mime</code>
        is a good indicator of 1.6.0_10+.
        </li>
        </ul>
    </li>
    </ul>
    
    </body>
    </html>
    

    mimetypes.js

    // As a version string, this might be '1.4.2_31'.  
    // I.E. it is not a 'number' but a 'string' and therefore must be treated as a string.
    var highestVersion = 'undefined';
    
    var mimes = window.navigator.mimeTypes;
    var plugins = window.navigator.plugins; 
    
    function isJava() {
        return (
            typeof(navigator.javaEnabled) !== 'undefined' &&
            navigator.javaEnabled());
    }
    
    function getVersion() {
        var version = 0;
        if (isJava()) {
            version = 1.1;
        }
        for (var ii=0; ii<mimes.length; ii++) {
            var t = mimes[ii].type;
            if (t.indexOf("java")>0 &&
                t.indexOf("jpi")>0 &&
                t.indexOf("applet")>0
                ) {
                var parts = t.split("=");
                version = parts[parts.length-1];
            }
        }
        if (highestVersion=='undefined') highestVersion = version;
        return version;
    }
    
    function isJWS() {
        var ver = highestVersion;
        var className = false;
        if (ver>'1.0') {
            className = undefined;
        }
        if (ver>'1.4.2') {
            className = true;
        }
        return className;
    }
    
    function isPlugin2() {
        var ver = highestVersion;
        var className = false;
        if (ver>'1.0') {
            className = undefined;
        }
        if (ver>'1.6.0_10') {
            className = true;
        }
        return className;
    }
    
    var versionFamily = [
        '1.9.0', '1.8.0', '1.7.0',
        '1.6.0', '1.5.0', '1.4.2'
    ];
    
    function getIEVersion() {
        for (var i=0; i<versionFamily.length; i++) {
            if  (testUsingActiveX(versionFamily[i])) {
                return versionFamily[i];
            }
        }   
        return false;
    }
    
    if (isIE() && getVersion()=='1.1') {
        highestVersion = getIEVersion();
    }
    
    function isIE() {
        return navigator.appName=='Microsoft Internet Explorer';
    }
    
    function testUsingActiveX(version) {
        var objectName = 'JavaWebStart.isInstalled.' + version + '.0';
    
        // we need the typeof check here for this to run on FF/Chrome
        // the check needs to be in place here - cannot even pass ActiveXObject
        // as arg to another function
        if (typeof ActiveXObject == 'undefined' || !ActiveXObject) {
            alert('[testUsingActiveX()] Browser claims to be IE, but no ActiveXObject object?');
            return false;
        }
    
        try {
            return (new ActiveXObject(objectName) != null);
        } catch (exception) {
            return false;
        }
    }
    
    function get3CellRow(cell1, cell2, cell3) {
        var s = "" +
            "<tr>" +
            "<td class='" +
            getClassName(cell1) +
            "'>" +
            cell1 +
            "</td>" +
            getDataStyledCell(cell2) +
            "<td class='" +
            getClassName(cell3) +
            "'>" +
            cell3 +
            "</td>" +
            "</tr>" +
            "";
    
        return s;
    }
    
    function getDataStyledCell(value) {
        var s = "<td class='datum " +
            getClassName(value) +
            "'>" +
            value +
            "</td>";
    
        return s;
    }
    
    function getClassName(val) {
        var className = undefined;
    
        if (
            (val) ||
            (!val) ||
            (val!=="undefined")
            ) {
            className = val;
        }
    
        return className;
    }
    
    function getBrowserInfo() {
        var s = "";
    
        var props = [
            'appCodeName','appName','appVersion',
            'userAgent',
            'platform','cookieEnabled'
        ];
    
        s += "<table border='1'>";
        for (var i=0; i<props.length; i++) {
            s+= "<tr>";
            s+= "<td><b>";
            s+= props[i];
            s+= "</b></td>";
            s+= "<td>";
            s+= navigator[props[i]];
            s+= "</td>";
            s+= "</tr>";
        }
        s += "</table>";
    
        return s;
    }
    

    请注意(被警告)这个脚本是由我编写的,我是一名 Java 程序员。 Java 程序员通常是编写 JS 的地球上最糟糕的人,因为我们愚蠢地倾向于假设。 “它是 JavaScript,它有多难?”。

    写出真正好的 JavaScript 确实是一门艺术。

    更糟糕的是,这是为了以后改进而被“破解”的实验性代码,但该项目被放弃了,“后来”从未到来。

    告诫购买者。

    【讨论】:

    • 嘿伙计,这看起来不错,但在 IE 中没有显示详细信息。
    • 是的,我注意到你最初的问题特别提到了 IE,但很快就被删除了。 IE 是最难确定此类信息的浏览器之一,因为它 支持几乎所有其他浏览器都支持的 mime-types 对象。你看过我包含截图的编辑吗?当时我对 IE 的唯一想法(我想完全排除 deployJava 脚本)然后“咬紧牙关”并插入一个 Java 1.1 兼容的小程序来完成其余的检查,但这当然会调用非常同样的警告。对不起,但我认为..
    • ..我们可以得出的结论是“不能做”,至少对于 IE 来说不是。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 2023-04-06
    相关资源
    最近更新 更多