简体   繁体   English

在Windows 10上使用JavaScript在Edge中检测“平板电脑/触摸模式”吗?

[英]Detecting “Tablet/Touch Mode” in Edge using JavaScript on Windows 10?

This question was asked before, but the answers are not exactly what I need. 之前曾问过这个问题,但答案并非我真正需要的。

I need to distinguish in Microsoft Edge if it's a tablet or not (Desktop). 如果不是平板电脑,我就需要在Microsoft Edge中加以区分(台式机)。

1) The following thread: Can you detect "Tablet Mode" in Edge and IE11 using JavaScript on Windows 10? 1)以下线程:是否可以在Windows 10上使用JavaScript在Edge和IE11中检测“平板电脑模式”?

worked indeed, but I'm afraid that in the next version Microsoft will change the behavior. 确实可以正常工作,但是恐怕Microsoft在下一版本中会更改行为。

How can I be sure that they won't? 我如何确定他们不会?

Answers with if condition of window.PointerEvent do not work at all, since it's defined in Desktop. 回答if condition of window.PointerEvent根本不起作用,因为它是在桌面中定义的。

I can't use CSS Media Queries Interaction media features as suggested here: Is there any way to detect if user has launched microsoft edge tablet or desktop browser? 我不能使用此处建议的CSS Media Queries Interaction媒体功能: 是否有任何方法可以检测用户是否已启动Microsoft Edge平板电脑或桌面浏览器?

Here are the hardware specific differences in the Edge browser capabilities: 以下是Edge浏览器功能中特定于硬件的区别:

The only differences are due to certain device-specific qualities – for example, codec support may be different on phones due to missing hardware acceleration, and Flash is not supported on Windows 10 Mobile. 唯一的区别是由于某些特定于设备的质量–例如,由于缺少硬件加速,电话上的编解码器支持可能有所不同,而Windows 10移动版不支持Flash。 Because Windows 10 Mobile has a different background model, RTC (Real-Time Communications) APIs are also currently not supported. 由于Windows 10移动版具有不同的背景模型,因此当前也不支持RTC(实时通信)API。 Finally, Windows 10 Mobile does not support Flash in order to provide a modern, touch-focused, and power-efficient experience appropriate for a mobile device. 最后,Windows 10移动版不支持Flash,以提供适用于移动设备的现代,注重触摸且节能的体验。 Because of this, Flash is not supported in Microsoft Edge in Continuum. 因此,Continuum中的Microsoft Edge不支持Flash。

To detect RTC capabilities, use the following code: 要检测RTC功能,请使用以下代码:

if (RTCRtpCapabilities)
  {
  initRTC();
  }
function initRTC()
  {
  var recvAudioCaps = RTCRtpReceiver.getCapabilities("audio"); 
  var recvVideoCaps = RTCRtpReceiver.getCapabilities("video"); 
  var sendAudioCaps = RTCRtpSender.getCapabilities("audio");
  var sendVideoCaps = RTCRtpSender.getCapabilities("video"); 
  }

Embedding a Flash movie which uses an ExternalInterface call would be the easiest way to detect Flash. 嵌入使用ExternalInterface调用的Flash电影是检测Flash的最简单方法。

The properties of the navigator object should be able to distinguish tablet from phone. navigator对象的属性应该能够区分平板电脑和手机。 For example: 例如:

navigator.cpuClass

should return x86 for Surface devices, but other for phones. 应该返回x86地表设备,但other的手机。

Also, the user agent changes when casting a phone display to a TV. 同样,当将电话显示器投射到电视上时,用户代理也会更改。 It goes from: 它来自:

  • Microsoft Edge UA (Mobile) Microsoft Edge UA(移动版)

     Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; <Device>) AppleWebKit/<Rev (KHTML, like Gecko) Chrome/<Rev> Mobile Safari/<Rev> Edge/<Rev> 

to: 至:

  • Microsoft Edge UA (Continuum) Microsoft Edge UA(连续体)

     Mozilla/5.0 (Windows NT 10.0; ARM) AppleWebKit/<Rev> (KHTML, like Gecko) Chrome/<Rev> Safari/<Rev> Edge/<Rev> 

compared to the desktop: 与台式机相比:

  • Microsoft Edge UA (Desktop) Microsoft Edge UA(台式机)

     Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/<Rev> (KHTML, like Gecko) Chrome/<Rev> Safari/<Rev> Edge/<Rev> 

References 参考文献

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

相关问题 你能在Windows 10上使用JavaScript检测Edge和IE11中的“平板电脑模式”吗? - Can you detect “Tablet Mode” in Edge and IE11 using JavaScript on Windows 10? 如何检测Windows 10是否处于平板电脑模式 - How to detect if Windows 10 is in tablet mode 如何使用 Delphi 检测 Windows 10 是否处于平板电脑模式? - How to detect if Windows 10 is in tablet mode with Delphi? Windows 10平板电脑模式注册表设置:“当此设备自动打开或关闭平板电脑模式时” - Windows 10 tablet mode Registry setting: 'When this device automatically switches tablet mode on or off' 了解 Windows 10 何时处于平板电脑模式 - Windows 10 / Windows 10 Mobile - Know when Windows 10 are Tablet Mode - Windows 10 / Windows 10 Mobile 对话框在Windows 10 Tablet模式下显示在父级后面 - Dialog shows behind parent in Windows 10 Tablet Mode Windows 10平板电脑模式下的Python / PyQt5全屏应用程序 - Python/PyQt5 fullscreen application on Windows 10 in Tablet mode 如何在Windows窗体应用程序中检测Windows 10何时进入平板电脑模式? - How can I detect when Windows 10 enters tablet mode in a Windows Forms application? Windows 10平板电脑模式注册表设置:记住我上次使用的内容 - Windows 10 tablet mode Registry setting: Remember what I last used 使用 python 在 Windows 10 上检测 USB 设备插入 - Detecting USB Device Insertion on Windows 10 using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM