有什么方法可以检测用户是否启动了Microsoft Edge平板电脑或桌面浏览器? [英] Is there any way to detect if user has launched microsoft edge tablet or desktop browser?

查看:134
本文介绍了有什么方法可以检测用户是否启动了Microsoft Edge平板电脑或桌面浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft Edge浏览器针对Windows 10平板电脑和台式机返回相同的用户代理.因此,请通过任何JavaScript功能或用户代理检测或任何其他方式帮助我区分micosoft edge平板电脑和台式机浏览器.

Microsoft edge browser is returning the same user agent for both windows 10 tablet and desktop. So please help me in differentiating micosoft edge tablet and desktop browsers through any javascript features or useragent detection or any other way.

注意:通常,我们通过指针事件来区分平板电脑和台式机浏览器. 平板电脑支持指针事件,而台式机不支持. 在Windows 10中,甚至台式机都支持指针事件

Note: Normally we differentiate tablet and desktop browsers by pointer events. tablet supports pointer events while desktop doesnt support. In windows 10 even desktop is supporting pointer events

推荐答案

不同于Windows 8/8.1,只有一个Microsoft Edge浏览器,而不是沉浸式"触摸友好浏览器和常规的台式机win32应用程序.因此,您无法检测到UA字符串的差异,因为没有差异.

Unlike Windows 8/8.1 there is only one Microsoft Edge browser, rather than an "immersive" touch friendly browser and regular desktop win32 app. As such you can’t detect the difference with the UA string, as there is no difference.

但是,如果您的用例是为触摸设备(平板电脑和敞篷车,二合一等)提供触摸友好的布局,并为仅鼠标和键盘的用户提供更紧凑的布局,则可以在CSS.

However, if your use-case is to give touch friendly layout for touch devices (tablets and convertibles, 2-in-1s, etc) and a more compact layout for mouse and keyboard only users, you can use feature detection in CSS for this.

为此,您可以使用CSS Media Queries Interaction媒体功能.

For this you can use CSS Media Queries Interaction media features.

如果要检测是否有触摸屏:

If you want to detect that there is a touch screen:

@media (pointer: coarse) { 
    ...styles for touch screen...
}

如果您要检测用户无法悬停(触摸屏上的常见问题):

If you want to detect that the user can’t hover (a common issue on touch screens):

@media (hover: none) {
   ... styles ...
}

但是重要的是要指出,这报告了主要的指针设备.在诸如敞篷车之类的机器中,可能会有触控板/鼠标和触摸屏,它可能会报告触摸屏的值.

It is however important to point out that this reports the primary pointing device. In machines such as convertibles where there can be a trackpad/mouse and touch screen, it may report the values for a touch screen.

有关详细信息,请参见规范.

See the spec for details.

这篇关于有什么方法可以检测用户是否启动了Microsoft Edge平板电脑或桌面浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆