Steven
Steven

Reputation: 2208

Get Adobe Reader version using Javascript

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

Upvotes: 1

Views: 5732

Answers (2)

Yi Jiang
Yi Jiang

Reputation: 50105

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/

Upvotes: 1

Steven
Steven

Reputation: 2208

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

Upvotes: 0

Related Questions