从网站重定向到Android应用程序?

 水源水足 发布于 2022-12-23 17:19

当用户打开网站时,我希望发生以下两种情况之一:

    如果安装了应用程序mycoolapp,则使用自定义URL方案将用户重定向到应用程序mycoolapp://

    如果未安装该应用程序,请保留在当前页面上,而不发布或重定向到未知页面或错误弹出窗口.

案例1很简单,您可以使用以下代码:

window.location = "mycoolapp://"; 

如果应用程序安装在设备上,这将有效.未安装应用程序时,它会将用户重定向到未知的空白页面.

对于案例2,我有一个使用iFrame的解决方案,它在iOS和原生Android浏览器上运行良好.它不适用于Android版Chrome.

var redirect = function (location) {
    var iframe = document.createElement('iframe');
    iframe.setAttribute('src', location);
    iframe.setAttribute('width', '1px');
    iframe.setAttribute('height', '1px');
    iframe.setAttribute('position', 'absolute');
    iframe.setAttribute('top', '0');
    iframe.setAttribute('left', '0');
    document.documentElement.appendChild(iframe);
    iframe.parentNode.removeChild(iframe);
    iframe = null;
};    

redirect('mycoolapp://');

安装应用程序后,它正在使用原生Android浏览器,但在Chrome for Android上则没有重定向.页面上没有任何反应.

如何在未安装应用的情况下重定向到适用于Android版Chrome的应用,而无需重定向到空白页?

编辑:我知道您可以使用Intent

window.location = "intent://#Intent;package=com.mycoolapp;scheme=mycoolapp;launchFlags=268435456;end;";

这不是我想要的,因为如果没有安装该应用,它会在Google Play上启动应用页面.有没有办法,它不会重定向到谷歌播放?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有