简体   繁体   English

如何在使用JavaScript的非IE浏览器中检测高于8的Adobe Acrobat版本之间的差异

[英]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. 我知道从版本8开始,Adobe Reader插件的名称已更改为“适用于Firefox和Netscape的Adobe PDF插件”,并且不包含任何版本信息。 However, the version information does appear in the "Plugins" tab when viewing Firefox Add-ons. 但是,在查看Firefox Add-ons时,版本信息会显示在“插件”选项卡中。 Does anyone know where that information comes from, and if it's possible to access that value with JavaScript? 有谁知道这些信息来自何处,以及是否可以使用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. Adobe已经在版本8和9之间对Acrobat Reader进行了重大更改,因此很难相信除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. 我仍然需要区分所有主流浏览器的版本8和9,但这里是我目前使用的代码适用于IE中的所有版本,所有版本都适用于Firefox,Safari和Chrome中的所有版本。 It also detects whether the plugin is installed but no version info for versions 8+ in Firefox, Safari and Chrome: 它还会检测插件是否已安装,但Firefox,Safari和Chrome中的版本8+没有版本信息:

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. 以下是为IE和FF中的所有版本检测Acrobat的代码。 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. 有关详细信息,请参阅http://www.oreillynet.com/cs/user/view/cs_msg/4055

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在非IE浏览器中使用JavaScript加载xml文件? - How to load xml-file with JavaScript in non-IE browsers? 如何通过JavaScript检测Firefox中安装的Adobe Acrobat版本 - How Do I Detect the Adobe Acrobat Version Installed in Firefox via JavaScript ContentFlow javascript 插件不在 IE 中加载,但在所有非 IE 浏览器中加载 - ContentFlow javascript plugin NOT loading in IE but loads in all non-IE browsers SSRS Report Manager javascript在非IE浏览器中针对Drop Down Menus失败 - SSRS Report Manager javascript fails in non-IE browsers for Drop Down Menus 在Adobe Acrobat X Pro中,如何使用javascript以acrobat pdf格式预填充文本字段? - In Adobe Acrobat X Pro, how do I use javascript to prefill text fields in an acrobat pdf form? sender._postBackSettings.panelID在非IE浏览器中返回null? - sender._postBackSettings.panelID returns null in non-IE browsers? 非IE浏览器中的基本动画异常慢 - Basic animation unusually slow in non-IE browsers 加载图像(JavaScript / DOM)后,滚动调整在非IE浏览器中无法正常工作; w / innerHTML的计时问题 - scroll adjustment not working correctly in non-IE browsers after loading an image (JavaScript/DOM); timing issue w/innerHTML 图表在非IE浏览器中显示在同一行,但在IE浏览器中显示在下一行 - Charts showing on the same line in non-IE browsers, but on the next line on IE browsers 它是如何工作的? -使用YUI进行非IE修复的Javascript函数 - How does it work? - Javascript function to make non-IE fixes using YUI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM