我正在尝试从 javascript 打开 Android 应用程序。如果 Android 应用程序安装在 Android 手机中,则会打开所需的应用程序。但如果没有安装 Android 应用程序,它应该会弹出窗口说:“您似乎没有安装应用程序,您想现在下载它吗?”。但我收到 net::ERR_UNKNOWN_URL_SCHEME 错误。我添加了下面的代码片段:
<html>
<head>
<script src="https://ajax.googleapis.com/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.com/store/apps/details?id=123';
}
}, 500);
}
</script>
</head>
<body onload="redirectToApp()">
<a id="link" href="" style="display: none">Link</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)