2013-06-27 69 views
2

我寫了一個協議處理程序來啓動Cisco Jabber設備。以下是我的代碼。某些Javascript可能檢測Cisco Jabber是否安裝?

<input onclick="javascript:window.location.href = 'movi:12345' 
type="button" value="Launch" /> 

它啓動Cisco Jabber,如果它安裝在客戶機上。但是如果沒有安裝,我想顯示警告並下載URL。怎麼可能?

+1

重複http://stackoverflow.com/questions/3411875 /如何檢測是否通過Web瀏覽器支持協議http://stackoverflow.com/questions/836777/how-to-detect-browsers-protocol-handlers – Prinzhorn

回答

2

下面的HTML文件應該成爲你的目的,請確保您更改jQuery的源文件鏈接到適合您自己的需要(head標籤內):

<html> 
<head> 
<script type='text/javascript' src='jquery-1.5.1.js'></script> 
<script type='text/javascript'> 

var protocolCheckerTimer = false; 
var installerSites = []; 
var currentProtocol = false; 
var protocolFound = false; 
var poppingUp = false; 

$(document).ready(function (e){ 

    $(window).bind('blur', interceptProtocolStartup); 
    $(document).bind('focusout', interceptProtocolStartup); 

    installerSites['movi'] = 'https://supportforums.cisco.com/docs/DOC-23292'; 
    installerSites['sip'] = 'http://www.linphone.org/eng/download/packages/'; 
    installerSites['skype'] = 'http://www.skype.com/en/download-skype/skype-for-computer/'; 
    installerSites['glow'] = 'http://www.glowpoint.com'; 

    $('a.protoco_handler').click(function (e) { 
     var sUrl = $(this).attr('href'); 
     var urlComponents = sUrl.split(':'); 
     currentProtocol = urlComponents[0]; 
     log('checking protocol for ' + currentProtocol); 
     protocolCheckerTimer = setTimeout(waitForProtocolHandler, 200); 
     $('#hidIFrame').attr('src', sUrl); 
     return false; 
    }); 

}); 


function waitForProtocolHandler() { 
    if (protocolFound === true) { 
     resetAll(); 
     return; 
    } 
    poppingUp = true; 
    if (confirm('Handler for protocol ' + currentProtocol + ' not found. Would you like to install?')) { 
      log('opening installer site ' + installerSites[currentProtocol] + ' for protocol ' + currentProtocol); 
      window.open(installerSites[currentProtocol]); 
     } 
     resetAll(); 
    } 

    function resetAll() { 
     protocolFound = false; 
     currentProtocol = false; 
     if (protocolCheckerTimer !== false) { 
      clearTimeout(protocolCheckerTimer); 
      protocolCheckerTimer = false; 
     } 
     poppingUp = false; 

    } 

    function interceptProtocolStartup() { 
     if (poppingUp === true) { 
      return; 
     } 
     log('protocol found, clearing timeout'); 
     resetAll(); 
    } 

    function log(msg) { 
     if (window.console) { 
      console.log(msg); 
     } 
    } 
</script> 
</head> 

<body> 
<ul> 
<li><a class='protoco_handler' href='movi:[email protected]'>Launch Jabber</a></li> 
<li><a class='protoco_handler' href='sip:[email protected]'>Launch Cisco</a></li> 
<li><a class='protoco_handler' href='skype:mdaliazam'>Launch Skype</a></li> 
<li><a class='protoco_handler' href='glow:[email protected]'>Launch Glowpoint :)</a>  </li> 
</ul> 

<iframe id='hidIFrame' style='display:none'></iframe> 
</body> 
</html>