disable forward button array version

using an array disable forward button in browser

by Eugen Sunic

JavaScript

adminMode = false;
  i = 0;
  array = [];
  //-------
  cnt = false;
  cnt2 = false;
  just = false;
  second_back = false;
  //-------
  message: any;
  popstate = false;
  default_page = '';
  subscription: Subscription;
  customHistory = [];
  index = -1;

  constructor(private translate: TranslateService, private location: PlatformLocation, private router: Router, private messageService: EnvironmentServiceSecond) {
    console.log("here: " + window.document.referrer);
    this.default_page = window.location.href;
    this.router.events
      .filter(event => event instanceof NavigationEnd)
      .subscribe(event => {
        if (!this.popstate) {
          this.customHistory.push(window.location.hash);   this.location.onPopState((e) => {
     if (typeof this.customHistory[this.customHistory.length - 1] === 'undefined') {
       window.history.back();
     }
     if (!this.cnt) {
       this.popstate = true;
       this.customHistory.pop();
       const lastEntry = this.customHistory[this.customHistory.length - 1];
       console.log(this.customHistory[this.customHistory.length - 1]);

       if (lastEntry !== undefined) {
       window.history.pushState(null, null, lastEntry);
       this.cnt = true;
       } else {
       window.history.pushState(null, null, '/#/');
   }
 } else {
     this.cnt = false;
      window.history.back();
   }

});
        if (lastEntry !== undefined) {
          window.history.pushState(null, null, lastEntry);
          window.history.back();
          this.cnt = true;
        } else {
          window.history.pushState(null, null, '/#/');
        }
      } else {
        this.cnt = false;
      }



    });

  }