简体   繁体   English

在 Javascript 中检测类似 Windows 或类似 Mac 的键盘

[英]Detect Windows-like or Mac-like keyboard in Javascript

My web app has a feature where the user can hold Ctrl (Windows, ctrlKey ) or Cmd (Mac, metaKey ).我的网络应用程序有一个功能,用户可以按住 Ctrl(Windows, ctrlKey )或 Cmd(Mac, metaKey )。 I want to provide help text telling the user they can do this.我想提供帮助文本告诉用户他们可以这样做。

What's a reliable way to detect a Mac-like keyboard?检测类 Mac 键盘的可靠方法是什么? Is navigator.platform.match(/mac/i) safe enough? navigator.platform.match(/mac/i)足够安全?

这似乎是可靠的:

const isMac = navigator.userAgent.includes('Mac');

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

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