I have the following small snippet of JavaScript, which works excellent to pop an alert when somebody might be leaving the form, while incomplete. However, I’m trying to first trigger a Toast with some small additional information that all works will be lost when continuing.
I’m unable to show the Toast before the window alert though, so it pops up only after. What would be a way to go about this? It’s not that they would have to interact with the Toast yet; I just want the small alert in the bottom right of the screen indicating that process will be lost.
<script>
window.onbeforeunload = () => {
console.log(window.in_progress);
const toastLiveExample = document.getElementById('liveToast')
const toast = new bootstrap.Toast(toastLiveExample)
toast.show()
if(window.in_progress > 0){
console.log(window.in_progress);
return true;
};
};
</script>