본문 바로가기
💻CODING/javascript

[js] 브라우저 종류 확인 (navigator.userAgent)

by 코딩하는 갓디노 2023. 2. 27.

[js] 브라우저 종류 확인 (navigator.userAgent)

 

브라우저 종류 확인 (navigator.userAgent)

const mobileTypeFn = () => {
    const uagent = navigator.userAgent.toLowerCase()
    const android_agent = uagent.search("android")
    const iphone = uagent.search("iphone")
    const ipad = uagent.search("ipad")

    if (android_agent > -1) { //안드로이드
        return 'android'
    }
    else if (iphone > -1 || ipad > -1) { //아이폰
        return 'iphone'
    }
    else return 'pc'
}

 

반응형

댓글