JavaScript 判断 Android 还是 iOS

JavaScript 大约 442 字

Android

function android() {
    return /Android/i.test(navigator.userAgent)
}

iOS

function iOS() {
    return [
        'iPad Simulator',
        'iPhone Simulator',
        'iPod Simulator',
        'iPad',
        'iPhone',
        'iPod'
    ].includes(navigator.platform)
        // iPad on iOS 13 detection
        || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
}

参考

StackOverflow: Detect if device is iOS

阅读 54 · 发布于 2021-06-24

————        END        ————

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批