Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Routing prevent back button #3359


User avatar
0
michaelhilgers created

Angular 2, Asp Core, Abp 1.5.0

Hi,

I try a lot of things to prevent the back button in the browser and on a mobile phone. If I'm on a modal i'd like to prevent the back button behavior

I try using jQuery like

$(document).on('keydown', function (event) {
            if (event.keyCode == 27) {
                // Prevent default (disable the back button behavior)
                event.preventDefault();

                // Close the modal
                self.close();
}

And then I use

window.addEventListener('onpopstate',
            // Add your callback here
            (event) => event.preventDefault()
        );

But it doesn't work... the page go always to the previous page.

How can I prevent this behavior if I'm on a modal

Thanks !!


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @MichaelHilgers,

    I think this is a browser behavior, not related to angular 2. You can find a better asnwer on the web I think.

    Thanks.