1

I am working on a project where the user should not be allowed to refresh the page using any of the following techniques:

Refresh, F5, CTRL + F5, CTRL + r... etc.

J0e3gan
  • 8,740
  • 10
  • 53
  • 80
user1625988
  • 73
  • 2
  • 6

1 Answers1

1
  document.addEventListener('DOMContentLoaded', function (e) {
            document.body.addEventListener('keydown', function (e) {
                if (e.keyCode == 116) {
                    e.preventDefault();
                }
            }, false);
  }, false);

Its nearly impossible to do such thing, you can prompt user from getting refreshed,

  var confirmOnPageExit = function (e) {
// If we haven't been passed the event get the window.event
            e = e || window.event;
            var message = 'Any text will block the navigation and display a prompt';
// For IE6-8 and Firefox prior to version 4
            if (e) {
                e.returnValue = message;
            }
// For Chrome, Safari, IE8+ and Opera 12+
            return message;
        };
        window.onbeforeunload = confirmOnPageExit;
Vicky Gonsalves
  • 11,593
  • 2
  • 37
  • 58