admin管理员组

文章数量:1531441

实现方式

页面控制

<div class="down-btn ios-btn" type='ios'></div>
<div class="down-btn and-btn" type='and'></div>

脚本控制

	// 是否是微信
    var isWx = navigator.userAgent.toLowerCase().indexOf('micromessenger') != -1;

    // 下载按钮 点击
	$(".down-btn").click(function(){
        var type = $(this).attr('type'); // 获取类型
        var ios_url = '应用在itunes上的地址';
        var and_url = '安卓apk下载地址';;
        var and_scheme = 'scheme://host/pathPrefix'; // 在应用约定的完整的 scheme 
        // 微信显示
        if(isWx) {
            return $(".tips").show(); // 提示层展示 微信端提示使用浏览器下载
        } 
        
        // web 处理 ios
        if(type === 'ios') {
            return window.location.href = ios_url;
        }

        // web 处理 and
        if(type === 'and') {
            window.location.href = and_scheme; // 尝试唤起
            t = Date.now(); // 设置当前时间
            // 唤起失败则打开下载页
            var timer = setTimeout(function() {
                clearTimeout(timer);
                // 1s 之后比较
                // 原理:唤起 app 会让浏览器的定时器变慢
                if (Date.now() - t < 1200) {
                    window.location.href = and_url; // 直接下载 app
                }
            }, 1000);
        }
    });

参考链接

  • https://blog.csdn/m0_37678565/article/details/68491444
  • https://blog.csdn/m0_37263637/article/details/78043664
  • https://blog.csdn/gf771115/article/details/73177153
  • https://blog.csdn/m0_37700275/article/details/81386910

本文标签: 公众方式app