2009-11-11 6 views
3

Actuellement, je travaille sur une page Web qui dira à l'utilisateur sur certaines configurations sur la machine client. De ce fait, il est également nécessaire de détecter si Adobe Reader est installé sur la machine client ou non. J'utilise ASP.NET/C#.Vérifiez si Adobe Reader est installé sur la machine client

J'ai regardé l'URL suivant pour la réponse "Check Adobe Reader is installed (C#)?" mais le code regarde dans le registre du serveur indique où IIS est installé et non l'ordinateur client où le navigateur est en cours d'exécution.

Est-il possible de détecter si Adobe Reader est installé sur l'ordinateur client et non sur le serveur hébergeant le site Web?

Répondre

3

pls, vérifier le script ci-dessous, il a bien fonctionné pour moi dans IE, FireFox et Chrome

<html> 
<body> 
<script type="text/javascript"> 
var found = false; 
var info = ''; 

try 
{  
    acrobat4 = new ActiveXObject('PDF.PdfCtrl.1');  
    if (acrobat4) 
    {  
     found = true;  
     info = 'v. 4.0';  
    } 
} 
catch (e) 
{ 
    //??? 
} 

if (!found) 
{ 
    try 
    { 
     acrobat7 = new ActiveXObject('AcroPDF.PDF.1'); 
     if (acrobat7) 
     { 
      found = true; 
      info = 'v. 7+'; 
     } 
    } 
    catch (e) 
    { 
     //??? 
    } 

    if (!found && navigator.plugins && navigator.plugins.length>0) 
    { 
     for (var i = 0; i<navigator.plugins.length; i++) 
     {       
      if (navigator.plugins[i].name.indexOf('Adobe Acrobat') > -1) 
      { 
       found = true; 
       info = navigator.plugins[i].description + ' (' + navigator.plugins[i].filename + ')'; 
       break; 
      } 
     } 
    } 
} 

document.write("Acrobat Reader Installed : " + found); 
document.write("<br />"); 
if (found) document.write("Info : " + info); 
</script> 
</body> 
</html> 

espérons que cette aide, ce qui concerne

+0

Cela a fonctionné pour moi, à la fois IE et FF – Vnuk

+0

nop, cela n'a pas fonctionné du tout. –

+0

Y at-il un moyen de vérifier dans le code asp.net si le lecteur Adobe installé est à jour, ou si une nouvelle mise à jour est disponible? –

1

je ce script et l'a appelé sur la fonction prêt: Note: j'ai utilisé les alertes ici juste pour savoir comment l'utiliser.

<script type="text/javascript"> 
    $(document).ready(function() { 
     alert(getAcrobatInfo().browser); 
     alert(getAcrobatInfo().acrobat === "installed"); 
     alert(getAcrobatInfo().acrobatVersion); 
    }); 


    var getAcrobatInfo = function() { 

     var getBrowserName = function() { 
      return '<%=Session["browser"].ToString()%>'; 
     }; 

     var getActiveXObject = function (name) { 
      try { return new ActiveXObject(name); } catch (e) { } 
     }; 

     var getNavigatorPlugin = function (name) { 
      for (key in navigator.plugins) { 
       var plugin = navigator.plugins[key]; 
       if (plugin.name == name) return plugin; 
      } 
     }; 

     var getPDFPlugin = function() { 
      return this.plugin = this.plugin || function() { 
       if (getBrowserName() == 'ie' || getBrowserName().toLocaleLowerCase() == 'internetexplorer') { 
        // 
        // load the activeX control 
        // AcroPDF.PDF is used by version 7 and later 
        // PDF.PdfCtrl is used by version 6 and earlier 
        return getActiveXObject('AcroPDF.PDF') || getActiveXObject('PDF.PdfCtrl'); 
       } 
       else { 
        return getNavigatorPlugin('Adobe Acrobat') || getNavigatorPlugin('Chrome PDF Viewer') || getNavigatorPlugin('WebKit built-in PDF') || getWebKitPlugin(); 
       } 
      }(); 
     }; 
     var getWebKitPlugin = function() { 
      for (var key in navigator.plugins) { 
       var plugin = navigator.plugins[key]; 
       if (plugin.name && plugin.name.substring(0, 6) == "WebKit" && (plugin.name.indexOf("pdf") != -1 || plugin.name.indexOf("PDF") != -1)) return plugin; 
      } 
     }; 
     var isAcrobatInstalled = function() { 
      return !!getPDFPlugin(); 
     }; 
     var getAcrobatVersion = function() { 
      try { 
       var plugin = getPDFPlugin(); 

       if (getBrowserName() == 'ie' || getBrowserName().toLocaleLowerCase() == 'internetexplorer') { 
        var versions = plugin.GetVersions().split(','); 
        var latest = versions[0].split('='); 
        return parseFloat(latest[1]); 

       } 
       if (plugin.version) return parseInt(plugin.version); 
       return plugin.name 


      } 
      catch (e) { 
       return null; 
      } 
     } 

     // The returned object 
     return { 
      browser: getBrowserName(), 
      acrobat: isAcrobatInstalled() ? 'installed' : false, 
      acrobatVersion: getAcrobatVersion() 
     }; 
    }; 
</script> 

ajouter également ce code derrière:

public void detectBrowser() 
    { //Set the Browser session variable 
     System.Web.HttpBrowserCapabilities browser = Request.Browser; 
     Session["Browser"] = browser.Browser; 
    } 

Hope it helps.

Questions connexes