当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery - disable other key listeners in javascript

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: