Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  176] [ 5]  / answers: 1 / hits: 31362  / 6 Years ago, sun, may 6, 2018, 12:00:00

How can I detect if the device is ONLY tablet? This script below is not working properly.



var ua = navigator.userAgent, tablet = /Tablet|iPad/i.test(ua);
alert(Tablet? + tablet);


I don't want check if is mobile and use else to show tablet. I want only a function to confirm if is tablet. How can I do that? Thanks


More From » javascript

 Answers
28

If you want to just use vanilla javascript you can use the navigator API





const userAgent = navigator.userAgent.toLowerCase();
const isTablet = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(userAgent);
console.log(isTablet)






https://developer.mozilla.org/en-US/docs/Web/API/Window/navigator




But i'd suggest using a librray such as wurfl.io




https://web.wurfl.io/#wurfl-js




if (WURFL.is_mobile === true && WURFL.form_factor === Tablet) {
// targetSmartPhoneDevices();
}




[#54500] Wednesday, May 2, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jericho

Total Points: 204
Total Questions: 98
Total Answers: 108

Location: Thailand
Member since Thu, Apr 22, 2021
3 Years ago
;