Say I have an HTML form on a page with a submit button. I've attached some logic to the form submit event to change the display to show a loading icon (in addition to posting the form to the server). However, if I press escape or click the browser's stop button, the submission event will stop but right now, the loading icon won't go away.
Is it possible to attach some JS logic to the "form interrupt" event to then clear the loading icon?
window.onabort looks as though it may have been designed for this purpose, but it doesn't appear to have any browser support.
Solutions which use either JQuery or plain vanilla JS are fine.
Edit to with clarifying code example
<form action="/myServerRoute" method="post">
<input type="submit" value="Submit form" onclick="DisplayLoadingAnimation();" />
</form>
<script>
function DisplayLoadingAnimation() {
alert('Imagine this manipulates the DOM to render loading elements.');
}
function HideLoadingAnimation() {
alert('Imagine this manipulates the DOM to clear loading elements.');
}
</script>
Imagine I click the "Submit form" button but then press the browser's stop button before the server can respond. How can I make it so that HideLoadingAnimation is executed when this happens?