- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What's the best way to detect a 'touch screen' device using JavaScript?
The best way to detect a ‘touch screen’ device, is to work around to see whether the touch methods are present within the document model or not.
function checkTouchDevice() { return 'ontouchstart' in document.documentElement; }
Here, you can also use it to detect mobile or desktop, like the following −
if (checkTouchDevice()) { // Mobile device } else { // Desktop }
Advertisements