Chrome扩展程序中的键盘快捷键 [英] Keyboard shortcuts in Chrome extensions

查看:186
本文介绍了Chrome扩展程序中的键盘快捷键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的Chrome扩展程序挂上一个键盘快捷键。我为此使用了一个jQuery插件: http://oscargodson.com/labs/jkey/

I'm trying to hook up a keyboard shortcut for my chrome extension. I'm using a jQuery plugin for this: http://oscargodson.com/labs/jkey/.

以下是我用来测试它的代码:

Here's the code I'm using to test it out:

$(document).ready(function() {
    function say_hello() {
       alert("hello!");
    }
    $(document).jkey('/', say_hello);
});

我现在在我的背景页面中有这个,但它不起作用。这种类型的代码应该放在后台页面,还是更适合内容脚本的东西?或者我应该把它放在别的地方吗?

I have this in my background page right now, but it doesn't work. Is this type of code something that should go in the background page, or something that's more appropriate for a content script? Or should I place it somewhere else entirely?

推荐答案

后台页面不能(通常)被关注或点击,因此他们永远不会收到事件。您必须将其作为内容脚本进行注入。

Background pages can't (ordinarily) be focused or clicked on, so they never receive events. You'd have to inject this as a content script.

请注意,这不适用于某些页面,包括新标签页。不幸的是,这是无法解决的。 :/

Note that this won't work on some pages, including the New Tab page. Unfortunately, there's no way around this. :/

这篇关于Chrome扩展程序中的键盘快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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