George Smith
George Smith

Reputation: 505

Forbid the user to refresh the page

I was thinking if there is a way to gain full control of the page / website by not allowing the user to refresh the page / website in any possible way. I am just curious if that is possible. I know that there are 1 million disadvantages but still.

Best regards,

George S.

Upvotes: 1

Views: 105

Answers (2)

user6245342
user6245342

Reputation: 108

You can intercept a refresh with something like this in which case the user is given a choice...

window.onbeforeunload=function(){return 'Page refresh has been intercepted to avoid an accidental loss of work';};

Upvotes: 2

LearningPhase
LearningPhase

Reputation: 1287

I have recently encountered the issue where people were hitting the refresh button couple of times on my website which was eventually causing problems at the server level. I put in some code at the client side to capture it and bypass the submit of the button. Also i put in some code at the server level to have a session entry which would store date time and would compare it when the next request came . it is was within a certain time frame it would be ignored.

if(e.which === 116) {
       console.log('blocked');
       return false;
    }
    if(e.which === 82 && e.ctrlKey) {
       console.log('blocked');
       return false;
    }

Upvotes: 0

Related Questions