0

I need to disable browser back button. Is there any way to detect browser back event using angularjs?

1 Answer 1

1

Why do you want to do this? If you use the angular router it should handle back and forward button clicks and go to the appropriate routes and therefore show the correct pages.

If there is a page you don't want the user to be able to go back to, you can call $location.replace() to replace the current history item instead of adding new history. For example

// current page is /cat/new, a link on this page calls newCat('fluffy')
scope.newCat = function createCat(catzName) {
     scope.cat = { name: catzName }
     // go to the details page for that cat 
     $location.path('/cat/' + catzName);
     // don't let the user go back to /cat/new
     $location.replace();
}
Sign up to request clarification or add additional context in comments.

1 Comment

because when I go back it mess up page contents with another state.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.