问题描述:

I want to right simple javascript chrome extension that disables the key listeners in the webpage.

for example, when I am in youtube and pressing "l" the video is moving forward. I want some simple code that stops it and allows me to create my own key listener.

Can I do something like this?

Thanks!

网友答案:

You could prevent the default behaviour of the keypress, and then check the event.keyCode to do custom functions:

$(document).on('keypress', function(event){ event.preventDefault(); // Check for the 'l' keycode if (event.keyCode == 108) { // Do what you want here! } });

This will prevent you from typing in comments and hitting spacebar to pause the video, etc.

相关阅读:
Top