我搜索并发现我可以使用 jQuery 模拟按键事件,但我对 jQuery 的了解很差,而且我不知道具体是如何实现的。
So I have a Greasemonkey script which manages 2 different webpages in 2 tabs.
I'd like to simulate/auto-execute CtrlShiftTab to go back to the previous tab automatically, this way I could change tabs in Firefox.
The problem is that it's not only a plain keypress, I need to simulate a Ctrl and Shift parts too.
我已将其添加到我的脚本中:
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
并尝试过:
function testEvents(){
var press = jQuery.Event("keypress");
press.which = 9;
$("whatever").trigger(press.ctrlKey + press.shiftKey + press.which);
}
没有成功。
我见过的一些链接:是否可以通过编程方式模拟按键事件? https://stackoverflow.com/questions/596481/simulate-javascript-key-events,
模拟jquery https://github.com/jquery/jquery-ui/blob/master/tests/jquery.simulate.js, and http://forum.jquery.com/topic/simulated-keypress-events http://forum.jquery.com/topic/simulating-keypress-events
JavaScript 不能用于通过模拟“快捷键”按键事件来触发默认行为。
由于 jQuery 只是编写 JavaScript 代码的一种不同方式,因此该限制也适用。
而且,由于 Greasemonkey 脚本基于 JavaScript,除了GM_*
方法,不可能编写切换选项卡的用户脚本。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)