2010-09-08 70 views

回答

0

我發現這一點,但它僅在Internet Explorer

function CheckAdobeVersion() { 


     var isInstalled = false; 
     var version = null; 
     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) { 
        return; 
       } 
      } 
      if (control) { 
       isInstalled = true; 
       version = control.GetVersions().split(','); 
       version = version[0].split('='); 
       version = parseFloat(version[1]); 
       return version; 
      } 
     } else { 
      // Check navigator.plugins for "Adobe Acrobat" or "Adobe PDF Plug-in"* 
     } 
    }  

任何想法我怎麼能得到它在Firefox或Chrome瀏覽器的工作原理?

Sp

+0

這應該被添加到原來的問題作爲一個編輯。這種不適用於任何非IE瀏覽器的明顯原因是因爲它使用ActiveX,這是專有的IE技術,所以「在其他瀏覽器上工作」不是一種選擇 - 您需要一種完全不同的方法。 – 2010-09-08 13:06:53

1

我修改了上面給非IE瀏覽器使用的代碼。

function CheckAdobeVersion() { 
    var isInstalled = false; 
    var version = null; 
    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) { 
       return; 
      } 
     } 
     if (control) { 
      isInstalled = true; 
      version = control.GetVersions().split(','); 
      version = version[0].split('='); 
      version = parseFloat(version[1]); 
      return version; 
     } 
    } else { 
     // Changes added in here 
     var plugins = navigator.plugins; 

     for(var i = 0; i < plugins.length; i++){ 
      if (plugins[i].name === "Adobe Acrobat"){ 
       version = plugins[i].version; 

       if(!version) { 
        version = plugins[i].description.split('"')[1]; 
       } 

       return parseFloat(version); 
      } 
     }  
    } 
} 

這使用navigator.plugins屬性來查找Adobe Reader。它適用於Firefox,Chrome,Safari和Opera,但我只是使用Reader的第9版進行了測試。

見真人版:http://jsfiddle.net/EGbY5/3/

相關問題