How can I find the mobile phone manufacturer using javascript on mobile browser

戏子无情 提交于 2019-12-25 07:47:49

问题


When the user visits my html page using the mobile browser, I want to know the device type and manufacturer. Is it possible?

If you open the web site www.mhltech.org/DoIHaveMHL.aspx from a mobile browser, it will identify the mobile device (like Motorola Moto G 2nd Gen 2014, Asus Google Nexus 7, etc.). It is what I am looking for.


回答1:


Perhaps you can use platform.js.

You can use platform.manufacturer; to solve your problem.




回答2:


In my case ua-parser-js was the best free solution. The minified version is on https://github.com/faisalman/ua-parser-js/tree/master/dist

What you need to do then is like

<script src="ua-parser.min.js" charset="utf-8"></script>
<script type="text/javascript">

var parser = new UAParser();
var result = parser.getResult();
alert(result.device.vendor);

</script>

I have tried platform.js and mobile-detect.js before this one, but their detection range was too narrow for my application, as my own phone was an "Unknown Phone" for them.




回答3:


Well,

You can use window.navigator.userAgent,

It will tell you the Device and browser information like

[Mozilla/5.0 (Linux; Android 6.0.1; Samsung SM-G900H Build/MMB29K) AppleWebKit/537.36 (KHTML, like Gecho) SamsungBrowser/4.0 Chrome/44.0.2403.133 Mobile Safari537.36]

and you just need to extract the bracket value which you need, and you got the device info.

To explore visit:
https://developer.mozilla.org/en-US/docs/Web/API/Navigator http://blog.teamtreehouse.com/exploring-javascript-device-apis



来源:https://stackoverflow.com/questions/41671325/how-can-i-find-the-mobile-phone-manufacturer-using-javascript-on-mobile-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!