What I want to do is that users open this page, this page will open the custom URL, if users have my app, then my app will be launched, or it will redirect to Google Play's website.
I found the code online. The code below has problems that type of variable state is not boolean. When I use my android phone to open this page, it will all execute no matter the codes in if or else.
Is thee anybody know how to fix it or it is impossible to do this?
if (navigator.userAgent.match(/android/i)){
var state = null;
try {
state = window.open("custom URL", '_blank');
} catch(e) {}
if (state) {
window.close();
} else {
window.location = "Google Play's Link";
}
}