我知道从版本 8 开始,Adobe Reader 插件的名称被更改为“Adobe PDF Plug-In for Firefox and Netscape”,并且不包含任何版本信息。但是,在查看 Firefox 附加组件时,版本信息确实会出现在“插件”选项卡中。有谁知道这些信息来自哪里,是否可以使用 JavaScript 访问该值?
Adobe 在版本 8 和 9 之间对 Acrobat Reader 进行了重大更改,因此很难相信在 IE 以外的浏览器中无法区分这两个版本。
我知道从版本 8 开始,Adobe Reader 插件的名称被更改为“Adobe PDF Plug-In for Firefox and Netscape”,并且不包含任何版本信息。但是,在查看 Firefox 附加组件时,版本信息确实会出现在“插件”选项卡中。有谁知道这些信息来自哪里,是否可以使用 JavaScript 访问该值?
Adobe 在版本 8 和 9 之间对 Acrobat Reader 进行了重大更改,因此很难相信在 IE 以外的浏览器中无法区分这两个版本。
我仍然需要区分所有主要浏览器的版本 8 和 9,但这是我目前使用的代码,它适用于 IE 中的所有版本,以及 Firefox、Safari 和 Chrome 中的所有版本高达 8。它还检测是否安装了插件,但在 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);
}
}
这是用于检测 IE 和 FF 中所有版本的 Acrobat 的代码。关键是它确实使用以下方法检测版本:
oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
if (oAcro)
{
acrobat.installed=true;
acrobat.version=x+'.0';
}
因此,通过一些自定义,您可以使用类似的东西来检测版本。
这是完整的代码:
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) {}
}
有关详细信息,请参阅http://www.oreillynet.com/cs/user/view/cs_msg/4055 。