如何绕过快速搜索Firefox功能并捕获正斜杠按键 [英] How to bypass Quick Search Firefox feature and capture forward slash keypress

查看:163
本文介绍了如何绕过快速搜索Firefox功能并捕获正斜杠按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我网站上的某个功能捕获正斜杠(/)的按键值'191'。由于其快速搜索功能,在除Firefox之外的每个浏览器上都能正常工'191'仍然会注册并执行操作(专注于输入字段,弹出帮助文本),但重点是快速搜索。

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.

我读了另一个StackOverflow问题,说Firefox捕获正斜杠为字符代码'0',但没有做任何事情。

I read in another StackOverflow question saying that Firefox captures the forward slash as character code '0', but that didn't do anything.

有没有办法可以忽略Firefox Quick搜索并控制正斜杠?使用JavaScript和jQuery。

Is there a way I can ignore the Firefox Quick Search and get control of the forward slash back? Using JavaScript and jQuery.

推荐答案

我同意质疑你是否应该使用该快捷方式很重要。但是,如果您决定(正如其他人那样 - 这也是gmail中的搜索快捷方式),您只需要捕获文档keydown事件(不是按键或键盘),然后阻止默认操作,它将及时拦截停止默认的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:

$(document).keydown(function(e) {
    var _target = $(e.target);
    var _focused = $(document.activeElement);
    var _inputting = _focused.get(0).tagName.toLowerCase()==="textarea" || _focused.get(0).tagName.toLowerCase()==="input";

    // / (forward slash) key = search
    if (!_inputting && e.keyCode===191) {
        e.preventDefault();
        $("#search-input").focus();
        return;
    }
});

这篇关于如何绕过快速搜索Firefox功能并捕获正斜杠按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆