[英]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.