简体   繁体   English

删除 twitter.com 上的 J 和 K 键事件

[英]remove J and K key events on twitter.com

I built a browser extension that extends twitter.com.我构建了一个扩展 twitter.com 的浏览器扩展。 It opens a jQuery UI modal window, and has some text inputs.它打开一个 jQuery UI 模态 window,并有一些文本输入。 When I type in those inputs, it works, except for the J and K keys.当我输入这些输入时,它可以工作,除了 J 和 K 键。 Those keys are part of some custom Twitter event (scrolling between tweets).这些键是一些自定义 Twitter 事件(在推文之间滚动)的一部分。 I can get all the keys to actually type the letter into the box except for those two.除了这两个之外,我可以获得所有将字母实际输入框中的键。

I want to know how to unbind the keypress stuff for those two keys so that I can get those two letters to type.我想知道如何取消绑定这两个键的keypress内容,以便我可以输入这两个字母。 Any ideas on how to unbind them?关于如何解除绑定的任何想法? I have tried catching the event and preventing the default on it...didn't help.我已经尝试捕捉事件并阻止它的默认值......没有帮助。 I have caught it and returned true/false, also no help.我已经抓住它并返回真/假,也没有帮助。 Please let me know.请告诉我。

This sounds very similar to a problem I had where google would alter the up and down arrow keys.这听起来与我遇到的问题非常相似,谷歌会改变向上和向下箭头键。 Here is where I solved it on SO after some help. 这是我在一些帮助后解决它的地方。 Basically I stopped the event like so (for me its up and down, find the keycodes for your j and k):基本上我这样停止了事件(对我来说,它的上下,找到你的 j 和 k 的键码):

if (event.keyCode == 40 || event.keyCode == 38)  {
    event.cancelBubble = true;
    event.stopPropagation();            
    return false;
}

Twitter appears to use jQuery for event binding. Twitter 似乎使用 jQuery 进行事件绑定。 From the JavaScript console, we can inspect these events:从 JavaScript 控制台,我们可以检查这些事件:

$(document).data('events').keydown;
$(document).data('events').keypress;
$(document).data('events').keyup;

Through basic trial and error, we can narrow our scope to the keypress event by removing these events and testing for the missing functionality.通过基本的反复试验,我们可以通过删除这些事件并测试缺失的功能,将 scope 缩小到按键事件。

// Results in j/k keys no longer moving up/down
$(document).data('events').keypress = [];

This of course is sort of a hack-and-slash approach, but useful for narrowing things down.这当然是一种 hack-and-slash 方法,但对于缩小范围很有用。

I ran into the same issue with textareas and input fields on Twitter.com when I built a browser extension to enhance the page.当我构建浏览器扩展以增强页面时,我在 Twitter.com 上遇到了与 textareas 和输入字段相同的问题。 I was able to get everything to work as expected by targeting the specific input and textareas that my extension created and then stoping the propagation of the keypress event.通过定位我的扩展程序创建的特定输入和文本区域,然后停止按键事件的传播,我能够让一切按预期工作。

$("selector-for-inputs-created-by-extension")
    .bind("keypress", function(e) {
        e.stopPropagation();
    });

Hope that helps clarify things.希望这有助于澄清事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用https://twitter.com/intent/user?user_id=进行跟随按钮删除按钮样式 - Using https://twitter.com/intent/user?user_id= for the follow button remove button styling 在我的主页上显示推文的twitter小部件:twitter.com - twitter widget that shows tweet on my homepage : twitter.com 今天的XSS onmouseover漏洞利用twitter.com - Today's XSS onmouseover exploit on twitter.com 获取twitter.Z4D236D9A2D102C5FE6AD1C5DAB73C2D22763D1CE2143A3755C1D0AD3AZ.Z4D236D9A2D102C5FE6AD1C5DA8C5上model内部object model的streamManager的引用 - Obtaining a reference to the streamManager of the internal object model on twitter.com 您如何使用jQuery来系统地更改Twitter.com上所有头像的src属性? - How can you use jQuery to change all the avatar images' src attribute on Twitter.com systematically? 在IE8中,当我指向Twitter.com的链接时,为什么会弹出“下载打开/另存为...”对话框? - In IE8, why is it that when I point a link to Twitter.com, it pops up a “download open/save as…” dialog? 如何删除ckeditor中的按钮和按键事件? - How can I remove button and key events in ckeditor? JavaScript的ATL COM事件 - ATL COM events for javascript Twitter Bootstrap附加事件未触发 - Twitter Bootstrap affix events not firing Twitter引导选项卡和javascript事件 - Twitter bootstrap tabs and javascript events
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM