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. :/