Trying to submit a form with GreaseMonkey, but the page stops working

安稳与你 提交于 2019-12-14 02:33:03

问题


I need to submit a form on a specific page, and it needs to click a radio button before it submits the form.

I got everything working, however when I let GreaseMonkey submit the form the page just returns a white page. As where if I would click Submit manually, it says 'Wait a second please..' and then goes on to another page.

If neccessary I can give you the URL of the form I am talking about.

This is the script I am using:

$(document).ready(function() {
    $("input[pmmethod=paypal]").click();
$(".submit-button").click();
});

回答1:


Sounds like a event handler is attached to the button, you could try to simulate a mouse click on it using native JavaScript instead of the jQuery method;

function simulateClick(node) {
    var ev = document.createEvent("MouseEvents");
    ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    return node.dispatchEvent(ev);
}

$(document).ready(function() {
    $("input[pmmethod=paypal]").click();
simulateClick( $(".submit-button")[0] );
});



回答2:


I know whay tou want...

I've altered the original script and now it will work!

http://userscripts.org/scripts/show/153026




回答3:


To submit a form using JavaScript, use submit() like this:

$(document).ready(function() {
    $("input[pmmethod=paypal]").click();
    $("#orderform").submit();
});


来源:https://stackoverflow.com/questions/13409322/trying-to-submit-a-form-with-greasemonkey-but-the-page-stops-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!