2010-02-17 46 views
3

我知道,從版本8開始,Adobe Reader插件的名稱已更改爲「用於Firefox的Adobe PDF Plug-In和Netscape「,並且不包含任何版本信息。但是,查看Firefox加載項時,版本信息確實出現在「插件」選項卡中。有誰知道這些信息來自哪裏,並且如果有可能通過JavaScript訪問該值?我如何使用JavaScript檢測非IE瀏覽器中Adobe Acrobat版本高於8的差異

Adob​​e在版本8和版本9之間對Acrobat Reader進行了重大更改,因此很難相信除IE之外的瀏覽器中無法區分這兩個版本。

回答

0

這裏是爲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瞭解更多詳情。

+0

不幸的是,這不會做我在找什麼。 Adobe改變了從版本8開始標籤Acrobat插件的方式,所以版本信息不再包含在內。使用此方法甚至不會捕獲版本8或9,因爲描述已更改爲「Adobe PDF Plug-In For Firefox和Netscape」。 我知道Firefox可以從某處檢測到插件版本,因爲它在您查看已安裝的插件時顯示。我只是不知道這些數據是否可以通過JavaScript訪問,因爲我無法在DOM中的任何地方找到它。 – bluehazetech 2010-02-22 15:03:44

2

我仍然需要區分所有主流瀏覽器的版本8和9,但這裏是我目前使用的代碼,適用於所有版本的IE以及Firefox,Safari和Chrome中的所有版本。它還檢測插件是否安裝,但沒有版本信息的版本8 +在Firefox,Safari和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); 
    } 
}