Can I disable browser refresh in my webapp?

2019-01-25 09:03发布

问题:

I want to disable refresh on my website. Is there any way to disable F5, Ctrl-R, or reload in a webpage?

回答1:

I have a suggestion. There is an answer box in this page.

(Here below with Your Answer label)

  • Type some text in it.
  • Then refresh this page

When you refresh there is some warning message displayed, I suggest you to display the similar warning message, instead of disabling the refresh functionality.



回答2:

window.onbeforeunload = function () {return false;}

This disables leaving the page unless the user confirms, not only refresh, so you'll have to code this yourself to get it to work.

You never said what you were doing with it so I left it at that.



回答3:

No, there is no way to disable it.

If you are trying to avoid the "Do you want to submit this action again?" dialog, use Post/Redirect/Get.



回答4:

Check for a cookie every time you enter the page. if the cookie is there then you know a refresh was made.

If the cookie is not there create one with zero duration (exist only till the browser still open)



回答5:

I don't know how to disable refresh clicking (i still need that one myself) Other than using a server side script to stop the "redirect" HOWEVER, I do know of EXTREMELY easy jQuery to disable F5:

function disableF5(e) { if (e.which == 116) e.preventDefault(); };
// To disable f5
$(document).bind("keydown", disableF5);
// To re-enable f5
$(document).unbind("keydown", disableF5);


回答6:

No, There is no such way. You can just warn user for not to refresh



回答7:

There may be some tricks that would work on some browsers, but there is nothing that could guarantee that they couldn't refresh the page. Browsers and web standards are wide open, so a user could easily hack up a browser to work around anything you implemented.

If refreshing would negatively impact the user experience, it is best to give them a textual warning.

If this is to fix a bug (such as a lack of idempotency), you should look into fixing the bug instead.



回答8:

There is a way to prevent the user from refreshing your page by pressing F5. Try this codes inside your body tag:

<body onkeydown="return (event.keyCode != 116)">


回答9:

If you want to disable ctrl+f5 , ctrl+R , f5 ,backspace then you can use this simple code. This code is working in Mozila as well as Chrome . Add this code inside your body tag:

<body onkeydown="return (event.keyCode == 154)">