closure in JavaScript

How to disable browser back button AngularJs?


AngularJs provides a useful event called location Change Start. The examples for $rootScope and $scope level looks like,

Example1 for $scope level as below,

//How to disable browser back button angularjs?
//Added event listner for disabled back button.
$scope.$on('$locationChangeStart', function(evnt, next, current){            
    alert("Your, browsers back button is disabled!");

    //Prevent browser's back button default action.
    evnt.preventDefault();            
});



Example2 for $rootScope level as below,

//Using $rootScope for event $locationChangeStart.
app.run(['$rootScope', function ($rootScope) {
     $rootScope.$on('$locationChangeStart', function (event) {
        event.preventDefault();
     });
}]);

I hope, It might help you! Thank you!

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.