javascript - Capture all dynamic form submits -
Some things for which I'm taking the account:
-
can form At any point on time, will be inserted into the dom. A Domain Ready Listener and Recurrence is not an option on
document.forms .
The logic of capturing it by adding a good one, it should work cross browser but it will be more than adding
jQuery to work. .
We are using a very heavy DOM manipulation framework and will not harm the solution.
I do not want to add the DOM entry audience because they are slower and frameworks that we often insert the inserts items into the dome.
Overriding
HTMLFormElement.prototype.submit works when the
.submit () program is called, but Not when the user triggers a form completely via browser interaction. I found that listening to the submitted event works for both cases, but to hear the incident, you need to reference each form instance. All form instances can be obtained through the
document.forms , but
document.forms is an HTMLCollection and there is no API to monitor changes only < code> works with nodes not
HTMLCollections . There are two approaches which I believe will work that seem quite messy.
-
setInterval can be used to monitor
document.forms and if a new form is
HTMLCollection has been added to the add listener in the form.
Monitor the events of document mutation and when a
form is inserted into the dom then add the listener.
document.forms length property.
Event listeners for
HTMLFormElement override constructor for a generic creation logic and then a
submit .
What to do about any advice? I am tilting towards using
setInterval , but this approach is not guaranteed to work in all situations.
To capture a user-submitted form, you can use the event delegation in the body Are there.
Then:
// Capture users submitted forms: document.body .addEventListener ('submit', function (e) {/ * `e. target` is being presented using the form `e.preventDefault () 'to prevent it from being submitted * false); // Capture programmatically submitted form: var _submit = HTMLFormElement.prototype.submit; HTMLFormElement.prototype.submit = function () {/ * `` This form is being presented using `_submit.call (this)` to deposit it * /};
Comments
Post a Comment