I am trying to determine if the end user is on a phone, tablet or PC
I searched Google for a while, apparently there is no easy solution.
Well, I think I shouldn't use Resolution, as some tablets currently have awesome resolutions.
I should not rely on orientation, because Windows8 laptops can just spin like tablets. (and responsive design is too complicated for my current project)
I am trying to use UserAgent (I thought that it also has its drawbacks), but it cannot make it work. Below is the connection of different versions on the Internet, which I use to distinguish a phone / tablet from a PC, they just do not work, and I have no idea why
var agents = ['android', 'webos', 'iphone', 'ipad', 'blackberry','iemobile','phone','mobile']; for(i in agents) { if(navigator.userAgent.toLowerCase().match('/'+agents[i]+'/i')) { return true; } } if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) { return true; } if( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i) || navigator.userAgent.match(/bada/i) || navigator.userAgent.match(/Bada/i) ){ return true; }
Matthew yang
source share