简体   繁体   中英

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 ). I want to provide help text telling the user they can do this.

What's a reliable way to detect a Mac-like keyboard? Is navigator.platform.match(/mac/i) safe enough?

这似乎是可靠的:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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