Execute javascript code straight before page submit

后端 未结 5 1526
半阙折子戏
半阙折子戏 2020-12-08 19:24

There are a few similar questions to this but none quite the same.

I want to know if there is an event that can be used to execute some JS before a page is submittin

5条回答
  •  醉酒成梦
    2020-12-08 20:21

    The following code will abort the submission from the window level, which will not submit the form.

    window.onsubmit = function() { alert('aborting submit'); return false; };
    

    Tested with IE11, so it should work for some legacy applications without jQuery.

提交回复
热议问题