h5 can’t tell whether the user has installed a certain app in the browser, but if the user installs the app and brings up the app, the page will lose focus
The app cannot be called up in WeChat, so add a prompt in WeChat to let the user open it in the browser.
$(".goBuy").click(function () {//Judging that the WeChat is opened and a prompt pop-up window is displayed. If the browser is opened, the app has been installed to open the app, and the download address is not installed
checkOutApp();
})
function checkOutApp() {
var isBlur = false;
// Call up the APP through the URL scheme
if(ua.match(/MicroMessenger/i)=="micromessenger") {//Whether WeChat is open
$(".commonMask").show();
$(".openInBrower").show();//WeChat opens the floating layer, WeChat does not support Scheme to open non-penguin applications
return false;
}else{
location.href = 'xinweifashion://';//app的 url scheme
setTimeout(function () {
if (!isBlur) {
location.href ='https://android.myapp.com/myapp/detail.htm?apkName=tv.xinwei.xinweifashion';//app download address
}
}, 1000);
}
// window loses focus every time
window.onblur = function () {
console.log('Lost focus');
isBlur = true;
};
var hiddenProperty = 'hidden' in document ? 'hidden' :
'webkitHidden' in document ? 'webkitHidden' :
'mozHidden' in document ? 'mozHidden' :
null;
var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
var onVisibilityChange = function () {
if (document[hiddenProperty]) {
console.log('Lost focus');
isBlur = true;
}
}
document.addEventListener(visibilityChangeEvent, onVisibilityChange);
}