we wanted to check whether application is installed or not on windows machine.
When this checkbox is checked then next time when we try to detect whether app is installed or not using Blur method it triggers the fail callback even it opens the app. Image
failure case: since this time app get opened automatically and no popup appears so fail call back also got triggered. image
Referring to https://github.com/ismailhabib/custom-protocol-detection solution I am able to detect whether the application is installed or not using the openUriWithTimeoutHack(url, successCb, failCb)
method.
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);
}
};
}
}
function openUriWithTimeoutHack(uri) {
var timeout = setTimeout(function () {
failCb();
handler.remove();
}, 1000);
//handle page running in an iframe (blur must be registered with top level window)
var target = window;
while (target != target.parent) {
target = target.parent;
}
var handler = _registerEvent(target, "blur", onBlur);
function onBlur() {
clearTimeout(timeout);
handler.remove();
successCb();
}
window.location = uri;
}
But the catch here is when the checkbox is checked then it does not lose focus from the browser because it opens the associated app directly thus triggering fail callback.
we have the solution for firefox using https://github.com/ismailhabib/custom-protocol-detection/issues/37#issuecomment-617962659. we tried this method in chrome but didn't work.