본문 바로가기
JS

detect iPhone X device with JavaScript

by memory-log 2020. 9. 21.

자바스크립트로 아이폰X 디바이스 감지하는 방법

IPhoneX Resolution

아이폰X 해상도

  • IPhone X : 1125 X 2436
  • IPhone XS : 828 X 1792
  • IPhone XMAX : 1242 X 2688
const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream
const ratio = window.devicePixelRatio || 1
const screen = {
  width: window.screen.width * ratio,
  height: window.screen.height * ratio,
}

const iosX = screen.width == 1125 && screen.height === 2436
const iosXr = screen.width == 828 && screen.height === 1792
const iosXMax = screen.width == 1242 && screen.height === 2688

if (iOS) {
  if (iosX || iosXr || iosXMax) {
    alert("iPhoneX Detected!")
  }
}

'JS' 카테고리의 다른 글

javascript find  (0) 2020.09.21
Javascript Some, Every  (0) 2020.09.21
replace & replaceAll 문자열 치환하기  (0) 2020.09.21
Slice & Splice  (0) 2020.09.21
JS Pattern  (0) 2020.09.21

댓글