使用Javascript获取Adobe Reader版本

时间:2010-09-08 10:39:04

标签: javascript adobe-reader

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

2 个答案:

答案 0 :(得分:1)

我修改了您上面提供的代码以使用非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,但我只用Reader 9的第9版进行了测试。

查看实时版本:http://jsfiddle.net/EGbY5/3/

答案 1 :(得分:0)

我找到了这个,但它只适用于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"*
        }
    }    

我有什么想法可以让它在Firefox或Chrome中运行?

SP