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.

2
  • 2
    Check out stackoverflow.com/q/3527041/988355 It might get you moving in the right direction Commented Oct 24, 2013 at 5:26
  • I recommend to find another project - you'll likely be forced to do other not-very-nice-near-to-impossible things... Commented Oct 24, 2013 at 5:32

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

1 Comment

This blocks refreshes by pressing F5, but the OP wants to prevent other methods of refresh too

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.