问题
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