美文网首页
H5判断是iOS还是android

H5判断是iOS还是android

作者: ONE2 | 来源:发表于2020-10-13 18:22 被阅读0次

iOS跳转到app store的应用详情页
android直接下载apk

function download() {
        var system = isIosOrAndroid()
        if (system == 1) {
            // 安卓
            var src = 'http://imtt.dd.qq.com/16891/26747DD8B125A8479AD0C9D22CA47BC9.apk?fsname=com.snda.wifilocating_4.2.91_3211.apk&csr=1bbd';
            var iframe = document.createElement('iframe');
            iframe.style.display = 'none';
            iframe.src = "javascript: '<script>location.href=\"" + src + "\"<\/script>'";
            document.getElementsByTagName('body')[0].appendChild(iframe);
        }
        else if (system == 2) {
            // iOS
            var src = 'https://itunes.apple.com/cn/app/id477927812'
            window.location.href = src
        }
    }

    function isIosOrAndroid() {
        var u = navigator.userAgent
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
        if (isAndroid) {
            return 1
        }
        var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        if (isiOS) {
            return 2
        }
        return 0
    }

相关文章

网友评论

      本文标题:H5判断是iOS还是android

      本文链接:https://www.haomeiwen.com/subject/dkljpktx.html