简体   繁体   English

Javascript识别浏览器平台是桌面还是移动(可能是/不是来自设备宽度-高度)

[英]Javascript identify whether the browser platform is desktop or mobile(may be/not from device width-height)

Question is as simple as above.问题和上面一样简单。

How to identify whether the browser platform is desktop or mobile with javascript如何使用javascript识别浏览器平台是桌面还是移动

I was trying facebook ads network and it only works for mobile platforms and not for desktop platform.I was wondering how they get it because when I use toogle device toolbar in chrome it identifies the device as not desktop platform and ad is displayed.Can I know the exact code or something smooth and easy as they use to identify whether its desktop of mobile ?我正在尝试 facebook 广告网络,它仅适用于移动平台而不适用于桌面平台。我想知道他们是如何获得它的,因为当我在 chrome 中使用工具栏时,它会将设备标识为不是桌面平台并显示广告。我可以吗?知道确切的代码或一些流畅和容易的东西,因为他们用来识别它的桌面是否移动?

The information is stored in navigator.userAgent variable.信息存储在navigator.userAgent变量中。 For desktop Chrome is userAgent like:对于桌面Chrome,userAgent 类似于:

"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"

for iPhone is like:对于iPhone就像:

"5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1" “5.0(iPhone;CPU iPhone OS 9_1,如 Mac OS X)AppleWebKit/601.1.46(KHTML,如 Gecko)版本/9.0 Mobile/13B143 Safari/601.1”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM