Skip to content Skip to sidebar Skip to footer

Detecting Device Manufacturer (i.e. Phone Brand) With Javascript

People have already talked about this issue on How can I find the mobile phone manufacturer using javascript on mobile browser and Detecting device brand What I need is a javascrip

Solution 1:

I've found a good list of the device models that I was looking for. To see it just go to https://deviceatlas.com/device-data/devices and click "browse by manufacturer" to reveal it. Now I can try and modify platform.js using that list or write something similar that will be able to detect the brands that I want. (Sure, it would be sweeter if somebody already did that for the top 10 or 20 manufacturers and shared his good code.)

EDIT 1: There is also mobile-detect.js which has a wider manufacturer detection range than platform.js as you may see it in their code on https://github.com/hgoebl/mobile-detect.js/blob/master/mobile-detect.js but still some major brands are either poorly covered or totally missing in that one too. Including every single manufacturer seems to be beyond the limits of monolancers anyway. It's like trying to chart the world-map on your own by traveling on foot. So it is not surprising that such an extensive service would have to be a paid service.

EDIT 2: Wait! I didn't know this existed: https://github.com/faisalman/ua-parser-js It is indeed muscular ! It looks like it is able to recognize my Sony phone. GOOD! (At least with mobile Chrome, it does. I tried mobile Firefox too but it doesn't work.) As for Huawei unfortunately it didn't recognize it. Still it may offer some use and to test it you can download it (preferably minified) and use some code like this

<scriptsrc="ua-parser.min.js"charset="utf-8"></script><scripttype="text/javascript">var parser = newUAParser();
var result = parser.getResult();
alert(result.device.vendor);

//this worked for mevar userDevice = result.device.vendor;
if(userDevice == "Sony")
{
// code to be run on Sony devices
}
</script>

Post a Comment for "Detecting Device Manufacturer (i.e. Phone Brand) With Javascript"