I am trying to open a android application from javascript. If the android application is installed in android mobile, it opens required application. But if android application is not installed, it should give me the popup saying, "You do not seem to have app installed, do you want to download it now?". But I am getting net::ERR_UNKNOWN_URL_SCHEME error. I have added the code snippet below:
<html>
<head>
<script src=".11.2/jquery.min.js"></script>
<script type="text/javascript">
function redirectToApp() {
$('#link').attr('href', "<scheme>://<package>/?<parameters>");
$("#link")[0].click();
setTimeout(
function() {
if (confirm('You do not seem to have app installed, do you want to download it now?')) {
window.location = '';
}
}, 500);
}
</script>
</head>
<body onload="redirectToApp()">
<a id="link" href="" style="display: none">Link</a>
</body>
</html>
I am trying to open a android application from javascript. If the android application is installed in android mobile, it opens required application. But if android application is not installed, it should give me the popup saying, "You do not seem to have app installed, do you want to download it now?". But I am getting net::ERR_UNKNOWN_URL_SCHEME error. I have added the code snippet below:
<html>
<head>
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function redirectToApp() {
$('#link').attr('href', "<scheme>://<package>/?<parameters>");
$("#link")[0].click();
setTimeout(
function() {
if (confirm('You do not seem to have app installed, do you want to download it now?')) {
window.location = 'https://play.google./store/apps/details?id=123';
}
}, 500);
}
</script>
</head>
<body onload="redirectToApp()">
<a id="link" href="" style="display: none">Link</a>
</body>
</html>
Share
edited Jul 20, 2024 at 11:41
VLAZ
29.2k9 gold badges63 silver badges84 bronze badges
asked Jan 4, 2018 at 12:42
Swathi DelampadySwathi Delampady
611 gold badge1 silver badge2 bronze badges
1 Answer
Reset to default 0You could try to wrap the click
in a try...catch. You said if the app is installed it works, so then you can assume if it fails that the app is not installed and then run the confirm
.
try {
$('#link').attr('href', "<scheme>://<package>/?<parameters>");
$("#link")[0].click();
} catch (error) {
if (confirm('You do not seem to have app installed, do you want to download it now?')) {
window.location = 'https://play.google./store/apps/details?id=123';
}
}
You may also want to check that the error passed to catch
is the net::ERR_UNKNOWN_URL_SCHEME
that you expected too but maybe it is enough like this?