I have been trying to find a way to target Huawei mobile devices so I can redirect them to the Huawei app store, but can't seem to find a solution. The one I have thought of so far is writing a regex to check for HUAWEI | Huawei | huawei in the string returned from the navigator.userAgent object.. but I am not sure if it will work for all such devices even though that is what i think looking at these sample userAgents
Is there an emulator or something like browserstack to try this out?
You can query the useragent to determine whether the current device is a Huawei phone.
Currently, Huawei browser provides UAs based on the HMS or GMS device type. The following are examples (the browser version number, HMS version number, GMS version number, and device information will change accordingly):
Mozilla/5.0 (Linux; Android 6.0.1; LYA-AL00;HMSCore/4.0.0 GMS/10.4 ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.64 HuaweiBrowser/10.0.3.102 Mobile Safari/537.36
Mozilla/5.0 (Linux; Android 6.0.1; LYA-AL00;HMSCore/4.0.0 ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.64 HuaweiBrowser/10.0.3.102 Mobile Safari/537.36
Mozilla/5.0 (Linux; Android 6.0.1; LYA-AL00;GMS/10.4 ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.64 HuaweiBrowser/10.0.3.102 Mobile Safari/537.36
Mozilla/5.0 (Linux; Android 6.0.1; LYA-AL00 ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.64 HuaweiBrowser/10.0.3.102 Mobile Safari/537.36
I don't know about targeting a specific type of mobile phone, but you can test the user agent string:
/**
* Determine the mobile operating system.
* This function returns one of 'iOS', 'Android', 'Windows Phone', or 'unknown'.
*
* @returns {String}
*/
function getMobileOperatingSystem() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
// Windows Phone must come first because its UA also contains "Android"
if (/windows phone/i.test(userAgent)) {
return "Windows Phone";
}
if (/android/i.test(userAgent)) {
return "Android";
}
// iOS detection from: http://stackoverflow.com/a/9039885/177710
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
return "iOS";
}
return "unknown";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With