浏览器上检测电脑是否安装某个应用程序

本文介绍了一种在网页上检测用户电脑是否安装特定应用程序的方法,如检测QQ安装情况,通过检查注册表项和使用iframe触发协议来判断。文章提供了详细的注册表路径和HTML示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近项目中需要在页面上判断用户电脑上是否安装某个应用程序,类似于手机上浏览器上的通过微信登录,然后页面就会去检测手机是否安装微信app的功能。

例如检测电脑上行是否安装QQ,腾讯的Tencent://Message协议注册表如下:
[HKEY_CLASSES_ROOT\TENCENT] @=”TencentProtocol” “URL Protocol”=”D:\\Program Files\\Tencent\\QQ\\Timwp.exe”
[HKEY_CLASSES_ROOT\TENCENT\DefaultIcon] @=”D:\\Program Files\\Tencent\\QQ\\Timwp.exe,1″
[HKEY_CLASSES_ROOT\TENCENT\shell]
[HKEY_CLASSES_ROOT\TENCENT\shell\open]
[HKEY_CLASSES_ROOT\TENCENT\shell\open\command] @=”\”D:\\Program Files\\Tencent\\QQ\\Timwp.exe\” \”%1\”"
此注册表所实现的就是当浏览器碰到 tencent://… 时,自动调用 Timwp.exe,并把 tencent://… 地址作为第一个参数传递给 Timwp.exe。

提示success则表示已安装。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
</head>
<body>
    <iframe id="trigger_protocol_ifrm" style="display:none"></iframe>
    <input id="protocolTxt" type="text" value="tencent://" />
    <input id="checkBtn"  type="button" value="check" />
    <script>
    document.getElementById('checkBtn').onclick = function(){
        var url = document.getElementById('protocolTxt').value;
        launchApplication(url, function(){
            alert('success');
        }, function(){
            alert('fail');
        });
    };
      
    var isDone = true;
    var timeout;
    var assistEl = document.getElementById('checkBtn');
    var triggerEl = document.getElementById('trigger_protocol_ifrm');
      
    function done(){
        isDone = true;
        assistEl.onblur = null;
        triggerEl.onerror = null;
        clearTimeout(timeout);
    }
    	
    function launchApplication(url, success, fail){
        if(!isDone)return;
        isDone = false;
        assistEl.focus();
        assistEl.onblur = function(){
            if(document.activeElement && document.activeElement !== assistEl){
                assistEl.focus();
            } else {
                done();
                success();
				
            }
        };
          
        triggerEl.onerror = function(){
            done();
            fail();
        };
  
  
        try{
            triggerEl.src = url;
        }catch(e){
            done();
            fail();
			
            return;
        }
  
  
        timeout = setTimeout(function(){
            done();
            fail();
        }, 3000);
    }
	
    </script>
</body>

</html>

 

 

参考链接:

https://blog.youkuaiyun.com/zhangyani_502000/article/details/81009907

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值