Here's a snippet of JavaScript that I have been working on. It currently pops up an alert when someone tries to leave a form without completing it. However, my goal is to display a Toast notification first with some additional information informing the user that all their work will be lost.
The issue I'm facing is that the Toast only appears after the window alert, but I want it to show before. Is there a way to achieve this? The Toast doesn't require any interaction at this point; I simply want it to provide a brief message in the bottom right corner of the screen indicating that the process will reset.
<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>