-2

Code for how to prevent user from refreshing the page either by using refresh button of browser or CTRL+F5 in angular js

Raja Singh
  • 1
  • 1
  • 1

1 Answers1

1

Well you cannot stop the user form manually refreshing the page, and not a good UX as well. Instead you can ask for confirmation for page reload. In JS we handle this using window.onbeforeunload:

window.onbeforeunload = function() {
    return "Your form progress will be lost, are you sure you want to reload this page?";
}

This reference shows you how to achieve this in Angular Js

Vishu
  • 338
  • 1
  • 10
  • Note that newer browsers [don't support a custom onBeforeUnload message](https://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own). – Haem Jun 13 '18 at 13:34