JavaScript 判断 Android 还是 iOS

JavaScript About 442 words

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

Views: 1,032 · Posted: 2021-06-24

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

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

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


Today On History
Browsing Refresh