views:

24

answers:

2

Hi,

What is the best way to get the adobe reader version in Javascript.

Thanks Sp

A: 

I have found this but it only works in 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"*
        }
    }    

Any ideas how i could get it to work in Firefox or chrome?

Sp

Steven
This should be added into the original question as an edit. The obvious reason for this not working on anything that isn't IE is because it uses ActiveX, which is proprietary IE technology, so "making this work on other browser" isn't an option - you need an entirely different approach for that.
Yi Jiang
A: 

I've modified the code you gave above to work with non-IE browsers.

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);
            }
        }    
    }
}

This uses the navigator.plugins property to look for Adobe Reader. It works for me with Firefox, Chrome, Safari and Opera, but I've only tested this with version 9 of Reader.

See the live version: http://jsfiddle.net/EGbY5/3/

Yi Jiang