简体   繁体   English

如何查找仅移动设备和平板电脑支持的javascript属性?

[英]How to find javascript properties which are only supported by mobile devices and tablets?

The basic problem is to detect mobile and tablet devices with JavaScript. 基本问题是使用JavaScript检测移动设备和平板设备。 I have a scrollbar plugin, and I only would like to display it on desktop browsers. 我有一个滚动条插件,我只想在桌面浏览器上显示它。 I would like to use the mobiles/tablets default scrollbar if possible. 我想尽可能使用手机/平板电脑的默认滚动条。

I decided to detect devices without the user-agent string, but focusing on mobile and tablet specific JS properties. 我决定检测没有用户代理字符串的设备,而是专注于移动设备和平板电脑特定的JS属性。 Here are the properties I found useful to detect mobile/tablet browsers. 这是我发现对检测移动/平板电脑浏览器有用的属性。 I would combine them to make it work as accurate as possible. 我将它们结合起来以使其尽可能准确。

  • window.screenX can not be different from 0 on mobile/tablet 在手机/平板电脑上,window.screenX不能与0相同
  • window.orientation is "undefined" on the most desktop browsers 在大多数桌面浏览器上,window.orientation是“未定义的”

I you can help me with this, I would appreciate it. 我可以为您提供帮助,我将不胜感激。 Is there any way to detect mobile/tablet browser in more accurate way? 有什么方法可以更准确地检测手机/平板电脑浏览器?

Here is the link to another SO that covers detecting devices using javascript or jQuery. 这是另一个SO的链接,该SO涵盖了使用javascript或jQuery检测设备的信息。

Edit: However it does appear to utilize userAgent in the more popular answer. 编辑:但是,它似乎确实在更流行的答案中利用了userAgent。 The second most popular answer does not use userAgent. 第二个最流行的答案不使用userAgent。 It uses CSS media queries to detect, and Javascript checks against the media query to determine the device. 它使用CSS媒体查询进行检测,并使用Javascript针对媒体查询进行检查以确定设备。

Hope this helps! 希望这可以帮助!

What is the best way to detect a mobile device in jQuery? 在jQuery中检测移动设备的最佳方法是什么?

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

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