Blog Posts

No results for undefinedPowered by Algolia

DailyLog

How to detect iPhone X device with JavaScript

September 04, 2020

자바스크립트로 아이폰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!")
  }
}