代码之家  ›  专栏  ›  技术社区  ›  Steven

使用Javascript获取Adobe Reader版本

  •  1
  • Steven  · 技术社区  · 15 年前

    用Javascript获取adobe reader版本的最佳方法是什么。

    2 回复  |  直到 12 年前
        1
  •  1
  •   Yi Jiang G-Man    15 年前

    我已经修改了你上面给出的代码,使之能够与非IE浏览器一起工作。

    function CheckAdobeVersion() {
        var isInstalled = false;
        var version = null;
        if (window.ActiveXObject) {
            var control = null;
            try {
                // AcroPDF.PDF is used by version 7 and later
                control = new ActiveXObject('AcroPDF.PDF');
            } catch (e) {
                // Do nothing
            }
            if (!control) {
                try {
                    // PDF.PdfCtrl is used by version 6 and earlier
                    control = new ActiveXObject('PDF.PdfCtrl');
                } catch (e) {
                    return;
                }
            }
            if (control) {
                isInstalled = true;
                version = control.GetVersions().split(',');
                version = version[0].split('=');
                version = parseFloat(version[1]);
                return version;
            }
        } else {
            // Changes added in here
            var plugins = navigator.plugins;
    
            for(var i = 0; i < plugins.length; i++){
                if (plugins[i].name === "Adobe Acrobat"){
                    version = plugins[i].version;
    
                    if(!version) {
                        version = plugins[i].description.split('"')[1];
                    }
    
                    return parseFloat(version);
                }
            }    
        }
    }
    

    它使用 navigator.plugins 属性来查找Adobe Reader。它适用于我的Firefox、Chrome、Safari和Opera,但我只在9版Reader上测试过。

    http://jsfiddle.net/EGbY5/3/

        2
  •  0
  •   Steven    15 年前

    我发现了这个,但它只适用于Internet Explorer

     function CheckAdobeVersion() {
    
    
            var isInstalled = false;
            var version = null;
            if (window.ActiveXObject) {
                var control = null;
                try {
                    // AcroPDF.PDF is used by version 7 and later
                    control = new ActiveXObject('AcroPDF.PDF');
                } catch (e) {
                    // Do nothing
                }
                if (!control) {
                    try {
                        // PDF.PdfCtrl is used by version 6 and earlier
                        control = new ActiveXObject('PDF.PdfCtrl');
                    } catch (e) {
                        return;
                    }
                }
                if (control) {
                    isInstalled = true;
                    version = control.GetVersions().split(',');
                    version = version[0].split('=');
                    version = parseFloat(version[1]);
                    return version;
                }
            } else {
                // Check navigator.plugins for "Adobe Acrobat" or "Adobe PDF Plug-in"*
            }
        }    
    

    服务提供商