views:

243

answers:

1

Hi All,

What exactly I am trying to do is add on more shortcuts to Google Chrome browser. As of now I am using window.addEventListener('keyup', keyCheck, false); I post a message then to the background page to carry out the relevant task.

I wonder if there is a way to achieve this when the current tab doesnt show any proper page (like newtab page, or extensions page, downloads page etc..)

+2  A: 

Hi Srivastan,

You currently cannot inject any scripts in chrome://* pages or about:* pages that includes newtab, extensions, version, etc.

An example on how you can do keyboard shortcuts would be something like this:

[source]

if (window == top) {
  window.addEventListener("keyup", keyListener, false);
}

// Keyboard keyup listener callback.
function keyListener(e) {
  // Must press ctrl key to validate.
  if (e.ctrlKey && e.keyCode && !e.metaKey) {
    chrome.extension.sendRequest({
      code: e.keyCode,
      alt: e.altKey,
      shift: e.shiftKey
    });
  }
}

You can override those pages, but that would be an ugly fix.

Mohamed Mansour
Mohamed, Thanks for replying! But can you tell me what exactly are you trying to do by 'if (window == top)' ?
Srivatsan Iyer
So you can add the 'keyup' listener on the page not for the frames inside the page. if (window == top) is for checking noframes.
Mohamed Mansour

related questions