About using JavaScript to intercept the submit method of the form
Posted on 2006-12-23 10:37 winder
Recently, I encountered the need to use JS script to uniformly intercept the submit method of the form in the page to modify the request when the page is implicitly submitted. The URL is simply implemented as follows:
Var OldSubmit;
var Form = Document.Forms [0];
If (Form! = NULLLLLL! = 'Undefined') {
// Form.oldsubmi t = FORM. submit; /// cover the submit function to achieve intercepting
Form.submit = function () {
// The operation before submit ..
// Drop the original function to submit
form.oldsubmit ();
}}}}
The above code will be intercepted when it is executed first when the page is loaded. For submissions that are displayed using the submit button, you can monitor the onsubmit event to achieve this. There are many methods for this and there is no big problem.