问题:
I'm looking for a function which return boolean value if user has mobile browser or not. 我正在寻找一个函数,如果用户具有或没有移动浏览器,则该函数返回布尔值。
I know that I can use navigator.userAgent
and write that function by using regex, but user-agents are too various for different platforms. 我知道我可以使用navigator.userAgent
并通过使用正则表达式来编写该功能,但是对于不同的平台,用户代理太多了。 I doubt that match all possible devices would be easy, and I think this problem has been solved before many times so there should be some kind of complete solution for such task. 我怀疑匹配所有可能的设备是否容易,而且我认为这个问题已经解决了很多次,因此应该为这种任务提供某种完整的解决方案。
I was looking at this site , but sadly the script is so cryptic that I have no idea how to use it for my purpose, which is to create a function which return true / false. 我当时在看这个站点 ,但是可悲的是脚本太神秘了,以至于我不知道如何使用它来创建一个返回true / false的函数。
解决方案:
参考一: https://stackoom.com/question/lktN/检测移动浏览器参考二: https://oldbug.net/q/lktN/Detecting-a-mobile-browser
来源:oschina
链接:https://my.oschina.net/u/4432649/blog/4328139