0

I was able to capture the event but, only in the case of F5, how do I prevent and Reload by the button too??

Example of how I did, to capture F5:

ngOnInit() {
    window.addEventListener("keyup", this.disableReloadPage);
    window.addEventListener("keydown", this.disableReloadPage);
}

disableReloadPage(e) {
     if ((e.which || e.keyCode) === 116) {
       alert("Não é possível recarregar essa página!");
       e.preventDefault();
     }
}
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • 2
    Simple answer - you can't. You could try listening for the `onbeforeunload` event, though, but that will fire on page close too. – Spectric Jul 29 '21 at 14:44
  • 1
    Need a close reason of "It is not possible" – epascarello Jul 29 '21 at 14:57
  • The "reload button" is in the browser's chrome, not in the DOM. The only thing Angular and other page-level JavaScript libraries have access to are those APIs exposed to the DOM. – Heretic Monkey Jul 29 '21 at 15:11

0 Answers0