前端(js) 判断本地是否安装了某个软件,如果安装则打开,如果没有安装则下载软件。

前端(js) 判断本地是否安装了某个软件,如果安装则打开,如果没有安装则下载软件。

需求场景

用户要求浏览器端可以直接打开本地安装的软件,如果没有安装就进行下载。

话不多说“开撸”

我本地是用内网通作为测试:

  1. 安装“内网通”;

  2. 注册表中查找“内网通”注册表信息;
    在这里插入图片描述

  3. 将“内网通”的注册信息添加到目标区域;在这里插入图片描述
    4.下载js文件

    jquery:
    http://www.jq22.com/jquery/jquery-3.4.1.zip

    protocolcheck.js
    https://github.com/ismailhabib/custom-protocol-detection
    在这里插入图片描述

  4. 废话不多说上代码:

    <!DOCTYPE html>
    <html lang="zh">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>监测平台</title>
      <style>
        h1 {
          position: absolute;
          top: 20%;
          left: 38.5%;
          color: white;
          font-size: 45px;
        }
    
        #indexBg {
          top: 45%;
          left: 15%;
          position: absolute;
          height: 200px;
          width: 72%;
          display: flex;
          justify-content: center;
        }
    
        .i_div {
          float: left;
          text-align: center;
          margin: 20px 73px;
        }
    
        .i_div img {
          cursor: pointer;
        }
    
        .i_div img {
          width: 70px;
          height: 70px;
          margin-top: 5px;
        }
    
        .i_div_text {
          width: 300px;
          height: 300px;
          font-size: 25px;
          color: white;
          /* background-color: cornsilk; */
        }
    
        .i_div_text span {
          cursor: pointer;
        }
      </style>
      <h1>监测平台</h1>
      <script>
        var url = "http://192.168.5.17";
      </script>
      <script src="js/jquery-3.4.1.js"></script>
      <script src="js/protocolcheck.js"></script>
    </head>
    
    <body style="background: url(bg.jpg) no-repeat 0 0 /cover;overflow: hidden;">
      <div id="indexBg">
    
        <div class="i_div" href="nwt://NWT?%1">
          <img src="./3.png" />
          <div id="pie_text" class="i_div_text">
            <span>内网通</span>
          </div>
        </div>
      </div>
      <script>
        function goto(flag) {
          switch (flag) {
            case 1: window.open(url + ":8080"); break;
            case 2: window.open(url + ":8082/dms/gologin.do"); break;
            default: window.open(url + ":8082/Download/内网通.exe"); break;
          }
        }
        function Exec(event) {
          window.protocolCheck($(this).attr("href"),
            function () {
              alert("protocol not recognized");
            });
          event.preventDefault ? event.preventDefault() : event.returnValue = false;
        }
        $(function () {
          $("div[href]").click(function (event) {
            window.protocolCheck($(this).attr("href"),
              function () {
                //alert("protocol not recognized");
                goto(3);
              });
            event.preventDefault ? event.preventDefault() : event.returnValue = false;
          });
        });
    
      </script>
    </body>
    
    </html>
    

参考于:
https://blog.csdn.net/evanxuhe/article/details/79240051
https://github.com/ismailhabib/custom-protocol-detection

  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值