1

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

4

2 回答 2

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属性来查找 Adob​​e Reader。它适用于 Firefox、Chrome、Safari 和 Opera,但我只用 Reader 版本 9 测试过它。

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

于 2010-09-08T13:41:51.687 回答
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

于 2010-09-08T13:02:18.273 回答