Preferably using JavaScript but would like to hear other ways too
Asked
Active
Viewed 1.7k times
9
-
Why do you want to do that? I ask because it's an unusual thing to want to do, and there may be a better way to solve your underlying problem. – Eric J. May 27 '10 at 02:20
-
You can only do it by disabling F5. I googled "Disable F5 Refresh" and got quite enough searches to figure it out quickly. – jsmith May 27 '10 at 02:22
-
5If you disable my `F5`, I'll try `CTRL+W` or `ALT+F4` next. – Dolph May 27 '10 at 02:23
-
Hi eric, I have a button on a screen that sends a web service. if i hit this button, and then hit F5, its going to send that web service twice. Thanks – Diskdrive May 27 '10 at 02:24
-
8@RoboShop: I would have the page send a unique token (randomly generated when you render the HTML page) along with the web service request. If it gets that token a second time, assume refresh was pressed and discard the request. – Eric J. May 27 '10 at 02:37
-
Also see question: http://stackoverflow.com/questions/2482059/disable-f5-and-browser-refresh-using-javascript – Jeach Feb 19 '14 at 04:20
4 Answers
17
This will disable F5, but not the actual refresh function:
document.onkeydown = function (e) {
if (e.keyCode === 116) {
return false;
}
};
On Chrome/XP, at least.

Matt
- 43,482
- 6
- 101
- 102
-
I hit the refresh button more often than I hit F5. If a user has just clicked one button, they might be more likely to click another button rather than hit a key. – detly May 27 '10 at 02:34
10
- Write a series of browser extensions which remove refresh functionality.
- Require in your Terms of Use that your users install (and use) your extension.
- Prosecute for non-compliance.
- Profit! (?)

Dolph
- 49,714
- 13
- 63
- 88
1
Actually, you can.. This little routine fixed it all for me..
I needed the other shortcuts, but not F5.
Private Sub WebBrowser1_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles WebBrowser1.PreviewKeyDown
If e.KeyCode = Keys.F5 Then WebBrowser1.WebBrowserShortcutsEnabled = False Else WebBrowser1.WebBrowserShortcutsEnabled = True
End Sub
Quick and dirty, but it works. Now, I can still use the Ctrl-B, I and U for editing, but I don't have to worry about refresh killing it!!
Enjoy!

thphoenix
- 181
- 4
0
You can't disable refresh.

nickf
- 537,072
- 198
- 649
- 721
-
1that wasn't the question. The question was to disable the "F5" refresh – Diskdrive May 27 '10 at 02:32
-
@RoboShop - I thought that was implied in my answer, though it looks like Matt has proved me wrong. – nickf May 27 '10 at 02:58