13 lines
404 B
TypeScript
13 lines
404 B
TypeScript
export function detectDevice() {
|
|
const ua = navigator.userAgent.toLowerCase();
|
|
const isTouch = navigator.maxTouchPoints > 1;
|
|
const width = screen.width;
|
|
|
|
if (/tablet|ipad/.test(ua)) return 'Tablet';
|
|
if (/mobile|iphone|ipod|android/.test(ua)) return 'Mobile';
|
|
|
|
if (isTouch && width < 768) return 'Mobile';
|
|
if (isTouch && width >= 768 && width <= 1280) return 'Tablet';
|
|
return 'Desktop';
|
|
}
|