使用 userAgent String 如何查找仅来自移动设备的请求?

using userAgent String How to find request comes from only mobile devices?

在 Android phone 的情况下,我检查了使用条件。 如果 (userAgent.contains("Mobile")) 但是如何检查 windows phone 或 i-phone?不适用于平板电脑。 如果是 window phone 我会检查 uc-browser 或 opera mini 等浏览器的许多条件吗? 请确认我 userAgent 是否包含通用字符串?使用这个我们识别请求来自移动设备?

您可以使用以下代码在 iOS 台设备中检测移动设备:

 if (navigator.userAgent.match(/(iPhone)/))
       return true;

您可以检测 android OS 的移动设备,如下面 link 中 Google 所述:

https://googlewebmastercentral.blogspot.com.au/2011/03/mo-better-to-also-detect-mobile-user.html

并且对于 Windows Phone 使用以下条件:

if(navigator.userAgent.match(/Windows Phone/i) || 
   navigator.userAgent.match(/iemobile/i) || 
   navigator.userAgent.match(/WPDesktop/i)){

    return true;
}