I have been looking for a way to permanently change the HTMLFormElement Javascript object's 'onsubmit' behavior. Let's suppose that one of my Javascript would contain the following code:
HTMLFormElement.prototype.onsubmit = function () {
this.submit();
// Make sure that you can only submit once.
this.onsubmit = function () {
return false;
};
return false;
};
The idea would be to simply prevent double submits on all forms of the document. I wasn't able to figure out how to do this since the above example is not working.
Is there a way to achieve this without looping through all existing HTMLElements after the document is loaded? A way which would be compatible with some older browser and also persist the behavior if you create new form elements using other scripts. (Vanilla JS only please)