9

Preferably using JavaScript but would like to hear other ways too

Diskdrive
  • 18,107
  • 27
  • 101
  • 167
  • 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
  • 5
    If 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 Answers4

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
  1. Write a series of browser extensions which remove refresh functionality.
  2. Require in your Terms of Use that your users install (and use) your extension.
  3. Prosecute for non-compliance.
  4. 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