需求场景
用户要求浏览器端可以直接打开本地安装的软件,如果没有安装就进行下载。
话不多说“开撸”
我本地是用内网通作为测试:
-
安装“内网通”;
-
在注册表中查找“内网通”注册表信息;
-
将“内网通”的注册信息添加到目标区域;
4.下载js文件protocolcheck.js
https://github.com/ismailhabib/custom-protocol-detection
-
废话不多说上代码:
<!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