I wanted to make a function that asks you if you really wanna leave the page when you try to leave, but where ever I press on my page it asks me this instead only when I try to leave, how do I fix it
The code:
document.addEventListener("DOMContentLoaded", function () {
//Dialog
document.addEventListener("click", function leave(){
if(confirm("You sure you wanna leave this page?")){}
else{
alert("Staying on page"+ " " + document.title +".");
event.preventDefault();
}
});