我需要设计一个包含按钮的HTML页面。按钮单击事件必须处理以下功能。
如果已安装应用程序,则打开相应的应用程序。
如果未安装应用,请打开Google Play商店链接。
如果已经安装了应用程序,或者我们将用户带到可以安装该应用程序的商店,有什么方法可以打开它?
HTML代码:
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Click me</button>
<script>
function myFunction() {
window.location.href = "https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=ticketnew.android.ui&hl=en";
}
</script>
</body>
</html>
JS Fiddle
最佳答案
Android的深度链接文档非常干净。您应该在Android应用程序代码上实现深度链接,以便单击Web链接,如果它安装在同一设备上,则可以直接打开您的应用程序。
https://developer.android.com/training/app-links