2010-02-08 47 views

回答

0

一種方式做到這一點 - 有可能是其他人 - 是檢查,看看創建對象標記之前無論是在navigator.plugins數組中的上市。像這樣的東西(一些示例代碼從最近的項目中剪切並粘貼):

function createVncServer(id) { 
     console.log(navigator.userAgent); 
     var vncDiv = document.getElementById("vncDiv"); 
     if (navigator.userAgent.indexOf("MSIE") > -1) { 
      vncDiv.innerHTML = "<object id='" + id + "' classid='CLSID:42832F4C-3480-4450-A6B5-156B2EFC408F' codebase='http://localhost:51150/Resources/WinVncCtlInstaller.CAB' />"; 
     } 
     else { 
      // On Mozilla browsers, check to make sure the plugin is installed before we try to instantiate it, to avoid the weird "plugins required" message. 
      var pluginInstalled = false; 
      for (var i = 0; i < navigator.plugins.length; i++) { 
       console.log(navigator.plugins[i].name); 
       if (navigator.plugins[i].name == 'Alanta Remote Desktop Server') { 
        pluginInstalled = true; 
       } 
      } 
      if (pluginInstalled) { 
       vncDiv.innerHTML = "<object id='" + id + "' type='application/x-alanta-vnc' />"; 
      } 
      else { 
       promptForDownload(); 
       return null; 
      } 
     } 
     var vncServer = document.getElementById(id); 
     try { 
      if (vncServer.Port > 0) { 
       clearDownloadPrompt(); 
       return vncServer; 
      } 
      else { 
       promptForDownload(); 
      } 
     } 
     catch (ex) { 
      promptForDownload(); 
     } 
    } 
相關問題