开发者

How do I detect the difference between Adobe Acrobat versions higher than 8 in non-IE browsers with JavaScript

I know that starting with version 8, the name of the Adobe Reader plugin was changed to "Adobe PDF Plug-In for Firefox and Netscape", and does not include any version information. However, the version information does appear in the "Plugins" tab when viewing Firefox Add-ons. Does anyone know where tha开发者_如何学运维t information comes from, and if it's possible to access that value with JavaScript?

Adobe has made significant changes to Acrobat Reader between version 8 and 9, so it's hard to believe that there's no way to distinguish between the two versions in browsers other than IE.


I still need to distinguish between versions 8 and 9 for all major browsers, but here's the code I'm currently using that works for all versions in IE, and all version up to 8 in Firefox, Safari and Chrome. It also detects whether the plugin is installed but no version info for versions 8+ in Firefox, Safari and Chrome:

var isInstalled = false;
var version = null;
var versionMessage = "";

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)
        {
            // Do nothing
        }
    }

    if (control)
    {
        isInstalled = true;
        version = control.GetVersions().split(',');
        version = version[0].split('=');
        version = parseFloat(version[1]);
    }
    if (isInstalled)
    {
        if (version >= 9.0)
        {
            alert("You are using Adobe Reader "+ version +". You may continue.");
        }
        else
        {
            alert("You are using Adobe Reader "+ version +". You must download Adobe Reader 9 to continue.");
        }
    }
}
else
{
    for(var i = 0; i < navigator.plugins.length; i++)
    {
        if(navigator.plugins[i].name == "Adobe Acrobat")
        {
            isInstalled = true;

            if(navigator.plugins[i].description == "Adobe PDF Plug-In For Firefox and Netscape")
            {
                versionMessage = "You are using at least version 8 of Adobe Reader. If you cannot see any of the PDF's listed on this page, you may need to upgrade to version 9.";
            }
            else
            {
                versionMessage = "You are using a version of Adobe Reader that is not supported. You must download Adobe Reader 9 to continue.";
            }
        }
    }
    if (isInstalled)
    {
        alert(versionMessage);
    }
}


Here is code to detect Acrobat for all versions in IE and FF. The key is that it does detect the version using:

oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
if (oAcro)
{
acrobat.installed=true;
acrobat.version=x+'.0';
}

So with a little customization you can use something similar to detect the version.

Here is the full code:

var acrobat=new Object();

acrobat.installed=false;
acrobat.version='0.0';

if (navigator.plugins && navigator.plugins.length)
{
for (x=0; x
{
if (navigator.plugins[x].description.indexOf('Adobe Acrobat') != -1)
{
acrobat.version=parseFloat(navigator.plugins[x].description.split('Version ')[1]);

if (acrobat.version.toString().length == 1) acrobat.version+='.0';

acrobat.installed=true;
break;
}
}
}
else if (window.ActiveXObject)
{
for (x=2; x<10; x++)
{
try
{
oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
if (oAcro)
{
acrobat.installed=true;
acrobat.version=x+'.0';
}
}
catch(e) {}
}

try
{
oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
if (oAcro4)
{
acrobat.installed=true;
acrobat.version='4.0';
}
}
catch(e) {}

try
{
oAcro7=new ActiveXObject('AcroPDF.PDF.1');
if (oAcro7)
{
acrobat.installed=true;
acrobat.version='7.0';
}
}
catch(e) {}

}

see http://www.oreillynet.com/cs/user/view/cs_msg/4055 for more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜