如何绕过 Firefox 快速搜索功能并捕获正斜杠按键
我正在捕获我网站上某个功能的正斜杠 (/) 的按键值“191”。由于其快速搜索功能,可以在除 Firefox 之外的所有浏览器上正常工作。 “191”仍然会注册并执行操作(焦点位于输入字段,弹出帮助文本),但焦点转到快速搜索。
我在另一个 StackOverflow 问题中读到,Firefox 将正斜杠捕获为字符代码“0”,但这没有执行任何操作。
有没有办法让我忽略 Firefox 快速搜索并控制正斜杠向后?使用 JavaScript 和 jQuery。
I'm capturing the key press value of '191' for the forward slash (/) for a feature on my site. Works fine on every browser except Firefox due to its Quick Search feature. The '191' still registers and the action is executed (focus on an input field, popup help text), but the focus goes to the Quick Search.
I read in another StackOverflow question saying that Firefox captures the forward slash as character code '0', but that didn't do anything.
Is there a way I can ignore the Firefox Quick Search and get control of the forward slash back? Using JavaScript and jQuery.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我同意质疑您是否应该使用该快捷方式很重要。但是,如果您决定(就像其他人一样 - 这也是 gmail 中的搜索快捷方式),您只需要捕获文档 keydown 事件(而不是 keypress 或 keyup),然后阻止默认操作,该操作将及时拦截以停止Firefox 的默认行为。另外,请务必检查用户是否尚未在文本字段中输入内容。这是一个简单的例子:
I agree it's important to question whether you should be using that shortcut. However, if you decide to (as others have- that's the search shortcut in gmail as well), you just need to capture the document keydown event (not keypress or keyup) and then prevent the default action, which will intercept in time to stop the default firefox behavior. Also, be sure to check that the user isn't already typing in a text field. Here's a quick example: