Home

Published

- 1 min read

get device type using javascript

img of get device type using javascript

The solution for this is noted below

get device type using javascript

Solution

   const getDeviceType = () => {
	const ua = navigator.userAgent
	if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) {
		return 'tablet'
	}
	if (
		/Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(
			ua
		)
	) {
		return 'mobile'
	}
	return 'desktop'
}

Try other methods by searching on the site. That is if this doesn’t work