![](/img/trans.png)
[英]Is there a reliable way to detect scrolling, on all devices, using javascript/jQuery?
[英]What is the reliable way to detect OS using Javascript?
根据 MDN,不建议使用navigator.userAgent 。 在我的应用程序中,我想要一个 del 键的快捷方式。
在 mac del 键(是退格键)中,charCode = 8。在 windows del 键中,charCode = 46。
我想对待两个 keyEvents 相同。 我目前正在使用 userAgent,但它不可靠,因为该属性可以被欺骗。 我想知道否则了解客户端操作系统的最佳方式是什么。
更多弃用的导航器属性navigator.appVersion navigator.platform
/* code objective */
if ((keycode == 8 && os == 'macintosh') || keycode == 46) {
//This is keyboard shortcut to perform delete
}
依靠 KeyboardEvent.metaKey 和 KeyboardEvent.Backspace 解决了我的问题
完整的键值 - https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
有关更多详细信息,请参阅: https : //developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key#Key_values
感谢@Teoli2003 的 twitter 回复 - https://twitter.com/Teoli2003/status/663995373766221824
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.