[英]Simulate an enter key press in Javascript with GreaseMonkey
What I want to do is fill up an input field, focus on it and press Enter to submit it. 我想要做的是填写一个输入字段,重点关注它,然后按Enter提交。 All of this automatically with GreaseMonkey on a specific page. 所有这些都可以通过GreaseMonkey在特定页面上自动完成。
Here is what I have so far, the field is filled up, but I can't get the keypress to work. 到目前为止,这里是我的工作,该领域已经填补,但我无法让按键工作。
var my_email = "test@maildrop.cc";
var field = document.getElementById('email');
var key_to_press = new Array;
key_to_press["key"] = "Enter";
key_to_press["keyCode"] = "13";
var ev = new KeyboardEvent("pressEnter", key_to_press);
field.value = my_email;
setTimeout(function() {
field.focus();
}, 2000);
setTimeout(function() {
field.dispatchEvent(ev);
}, 2000);
Here is some of the HTML from the page: 这是页面中的一些HTML:
<div class="form-group no-label required">
<label class="control-label" for="invite-email"></label>
<div class="input-group">
<input id="hiddenKid" type="hidden" value="BUXB4U"></input>
<input id="email" class="form-control" type="email" placeholder="E-mail Address" data-type="email" name="invite-email"></input>
</div>
</div>
<div id="submit_email" class="btn btn-submit-invite"></div>
Notice that there is also a button to submit the email, I could use it but I really don't know how to, since it is just a div probably handled by some other JS from the website... 请注意,还有一个按钮可以提交电子邮件,我可以使用它,但是我真的不知道如何提交,因为它只是一个div,可能由网站上的其他JS处理...
So does anyone know how can I make the enter keypress happen, or maybe click the button? 那么,有谁知道我该如何进行Enter键输入或点击按钮?
Finally I managed to click the button. 最终,我设法单击了按钮。 .click()
wasn't working because the event use .tap()
so here is what I just did: .click()
无法正常工作,因为该事件使用了.tap()
所以这就是我刚才所做的:
$('#submit_email').tap();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.