override existing onkeydown function

前端 未结 1 1705
野的像风
野的像风 2020-12-20 19:35

My extensions go through every input entered on an on any website that is loaded.

What I do is I consider every onkeydown and manipulate it if it has some value.

相关标签:
1条回答
  • 2020-12-20 20:00

    Instead of document.onkeydown = returnKey;, use

    document.addEventListener('keydown', returnKey, true);
    

    The most important part of this line is the third argument. When the value of this parameter is true, the event listener is triggered at capturing phase, which cannot be prevented using event.preventDefault(); or event.stopPropagation();.

    0 讨论(0)
提交回复
热议问题