网页拉起其他app

<!DOCTYPE html">
<html>
<body>
<script type="text/javascript">
(function () {
    var isiOS = navigator.userAgent.match('iPad') || navigator.userAgent.match('iPhone') || navigator.userAgent.match('iPod');
    var isAndroid = navigator.userAgent.match('Android');
    var isDesktop = !isiOS && !isAndroid;
    if (isiOS) {
        window.location = "itms-apps://itunes.apple.com/cn/app/qq-2011/id444934666?mt=8";
    } else if (isAndroid) {
        var host = "host";
        var scheme = "test";
        var package = "cn.mytest.app";
        window.location = "intent://"+host+"#Intent;scheme="+scheme+";package="+package+";end";
    } else {
        console.log("需要ios手机或android手机打开网页才有效!");
    }
})();
</script>
</body>
</html>

打开Android端的App的时候需要Android端的同学在Manifest里设置一些配置。

上面的代码比较适合在网页上做广告,但是对于Android端来说,还是给一个广告的http连接比较好;而ios的话,可以直接打开AppStore。

猜你喜欢

转载自blog.csdn.net/u013654125/article/details/80619374