samedi 22 août 2020

Prevent from leaving web application and redirecting to any other link

const adminLogOut = document.getElementById("adminLogOut");

adminLogOut.addEventListener('click', function () {
    window.alert("Are You sure You want to leave?");
});

window.onbeforeunload = function() {
    return "Are You sure You want to leave?"
}

The code above is going to prevent from logout and redirection. By redirection I mean leaving my web application stored on my local machine and run in Firefox. E.g. when I want to click on any bookmark in my browser, then .onbeforeunload function should prevent from leaving my application, but it works only when I want to leave the page which this JS code belongs to. Would You give any advice?




Aucun commentaire:

Enregistrer un commentaire