简体   繁体   中英

Error submitting a form with Greasemonkey

I'm using Greasemonkey to submit a form on an external site. However, I'm running into an issue since the form's submit button is named submit .

In firebug, document.filingform.submit(); is returning the error:

document.filingform.submit is not a function


Is there a way I can use Greasemonkey to either change the name of the submit button to something other than submit, or to call the submit() function of the form successfully?

Thanks!

It would be something like document.forms.filingform.submit(); , but don't do it that way!

This approach is liable to be blocked by sandboxing. Also, some pages require javascript functions to run on a legitimate submit. The most robust way to submit a page, and keep it and its server happy, is to "click" the submit button.

Code like:

var submitBtn   = document.querySelector ("form[name='filingform'] input[name='submit']");
var clickEvent  = document.createEvent ('MouseEvents');

clickEvent.initEvent ('click', true, true);
submitBtn.dispatchEvent (clickEvent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM