jkp
jkp

Reputation: 81288

Could I intercept and handle the new tab shortcut in JavaScript?

I'd like to add a feature to the awesome GleeBox project and it involves intercepting requests to create new tabs (so command-T on OS X). I know this sounds like a bad idea but bear in mind this is for an optional extension!

Anyway, is it possible to intercept a modified key-event that is used for a "system" function such as this?

Upvotes: 0

Views: 347

Answers (2)

Ninja rhino
Ninja rhino

Reputation: 116

Simply return false in the onkeydown event handler.

Be careful to ONLY do it if both keys are down though, not only on control and not only on t. That will mess up all other hotkeys the browser has.

I don't see why you would need ctrl+t though, that's one of the hotkeys in the browser that never should be blocked. (one of the main reasons people hate flash btw)

Upvotes: 1

afshin
afshin

Reputation: 204

If your write a keydown handler and inspect the event you get, there's an attribute called metaKey which indicates if the meta (command) key is down. You can probably use this to do what you want ... but you may be better off instead just using the T key or something like shift-T. Otherwise, you run the risk of irritating the user!

Upvotes: 0

Related Questions