问题描述
我已经根据https://gist.github.com/aaronk6/d801d750f14ac31845e8实现了一个解决方案,并且在chrome 85之前可以正常使用。最新的chrome Update Onblur未检测到开放协议处理程序弹出窗口。有没有一种方法可以识别使用Chrome 86新版本在Windows中注册的自定义协议。我已经实现了以下提到的代码,并且对于Firefox来说可以正常使用
function LinkClicked() {
launchUri($(this).attr("href"),function () {
// SUCCESS APPLICATION INSTALLED
},function () {
// PROTOCOL NOT REGISTERD IN REGISTRY
setTimeout(showAppInstallWarningMessage,4000);
},function () {
// STATUS CANNOT IDENTIFY
setTimeout(showAppInstallWarningMessage,4000);
});
}
function launchUri(uri,successCallback,noHandlerCallback,unkNownCallback) {
var res,parent,popup,iframe,timer,timeout,blurHandler,timeoutHandler,browser;
function callback(cb) {
if (typeof cb === 'function') cb();
}
function createHiddenIframe(parent) {
var iframe;
if (!parent) parent = document.body;
iframe = document.createElement('iframe');
iframe.style.display = 'none';
parent.appendChild(iframe);
return iframe;
}
function removeHiddenIframe(parent) {
if (!iframe) return;
if (!parent) parent = document.body;
parent.removeChild(iframe);
iframe = null;
}
browser = { isChrome: false,isFirefox: false,isIE: false };
if (window.chrome && !navigator.userAgent.match(/Opera|OPR\//)) {
browser.isChrome = true;
} else if (typeof InstallTrigger !== 'undefined') {
browser.isFirefox = true;
} else if ('ActiveXObject' in window) {
browser.isIE = true;
}
// EVALUATE msLaunchUri for IE 10+ browser in Windows 8+
if (navigator.msLaunchUri) {
navigator.msLaunchUri(uri,noHandlerCallback);
}
// Evaluating Blur-hack Chrome and FireFox
else if (browser.isChrome || browser.isFirefox) {
blurHandler = function () {
window.clearTimeout(timeout);
window.removeEventListener('blur',blurHandler);
callback(successCallback);
};
timeoutHandler = function () {
window.removeEventListener('blur',blurHandler);
callback(noHandlerCallback);
};
window.addEventListener('blur',blurHandler);
timeout = window.setTimeout(timeoutHandler,500);
window.location.href = uri;
}
else if (browser.isIE) {
popup = window.open('','launcher','width=0,height=0');
popup.location.href = uri;
try {
popup.location.href = 'about:blank';
callback(successCallback);
timer = window.setInterval(function () {
popup.close();
if (popup.closed) window.clearInterval(timer);
},500);
} catch (e) {
popup = window.open('about:blank','launcher');
popup.close();
callback(noHandlerCallback);
}
}
else {
iframe = createHiddenIframe();
iframe.contentwindow.location.href = uri;
window.setTimeout(function () {
removeHiddenIframe(parent);
callback(unkNownCallback);
},500);
}
}
解决方法
澄清一下,出于隐私和安全原因,JavaScript 有意无法检测本地协议处理程序;见this post。
停止工作的具体原因是 https://crbug.com/1137801。