序文
需要の背景:(ソフトウェアのみ検出.exeのWindowsシステムをサポートしています)、Webページをダウンロードし、クライアントソフトウェアをインストールするには、PCを検出する必要があります。そこのページのクライアントを開くためのボタンで。クライアントソフトウェアがインストールされている場合は、直接開く、またはダウンロードソフトウェア。iframeの下サポートWebページをダウンロード
クライアントのOpenメソッド
クライアントソフトウェアを介してカスタムプロトコルに登録レジストリを開きます。たとえば:JSコードlocation.href = 'baseonline://';
ビューのレジストリ方法:キーボードのプレスでは、レジストリエディタへのキャリッジリターンを、「+ Rに勝つ」regeditと入力し、操作ウィンドウを開きます
実現
- シナリオ1:最初にgithubの上のプログラムを見つけます
https://github.com/ismailhabib/custom-protocol-detection
。複数のブラウザの場合は、基本的にハッキング方法を達成しています。IFRAMEの内部にページを検出した場合、不十分な点は、検出方法、Googleのブラウザでは動作しません。テストページはIFRAME下にない場合は、オプション1を満たすことができるようになります。 シナリオ2:検出ページについては、iframeの下のページです。達成するための別の方法を探します。Googleのブラウザテストで。他はテストしていません。
グーグルでの2つのプログラムがテストされているので、あなたはオプション1との組み合わせでオプション2を置くことができます。より多くのブラウザの種類をカバー
スキーム2は、実施されています
/**
* uri 打开客户端的uri
* failCb 打开客户端失败回调
* successCb 打开客户端成功回调
*/
function openUriWithInputTimeoutHack(uri, failCb, successCb) {
let target = document.createElement('input')
target.style.width = '0'
target.style.height = '0'
target.style.position = 'fixed'
target.style.top = '0'
target.style.left = '0'
document.body.appendChild(target)
target.focus();
var handler = _registerEvent(target, "blur", onBlur);
console.log('focus')
function onBlur() {
console.log('blur')
successCb && successCb()
handler.remove()
clearTimeout(timeout)
document.body.removeChild(target)
};
//will trigger onblur
location.href = uri
// Note: timeout could vary as per the browser version, have a higher value
var timeout = setTimeout(function () {
console.log('setTimeout')
failCb && failCb()
handler.remove()
document.body.removeChild(target)
}, 1000);
}
function _registerEvent(target, eventType, cb) {
if (target.addEventListener) {
target.addEventListener(eventType, cb);
return {
remove: function () {
target.removeEventListener(eventType, cb);
}
};
} else {
target.attachEvent(eventType, cb);
return {
remove: function () {
target.detachEvent(eventType, cb);
}
};
}
}
// 测试
let protocalUrl = `baseonline://`
openUriWithInputTimeoutHack(protocalUrl, () => {
console.log('检测到,未安装客户端')
}, () => {
// 浏览器弹窗提示
console.log('检测到:已安装了客户端')
})
仕組み:クライアント、入力フォーカスを開くためのボタンをクリックします。1.ブラウザは、入力がフォーカスを失った、対応する登録番号とローカルシステムがクライアントソフトウェアをオープンポップするように指示されますことを検出し、クライアントのインストールを決定した場合。2.それ以外の場合は、1秒後にないポップ判断がインストールされていないクライアント。