tags:

views:

96

answers:

2

Possible Duplicates:
Disable browser's back button
How do I disable the F5 refresh on the browser?

Hi,

I created an application in C# that will download data from the internet (and this is done one time only) and put it in a webbrowser and this data should be static. I want to know if there is a way to disable the F5 key from doing a refresh?

I tried injecting javascript to disable F5 but it will still refresh the webbrowser.

+4  A: 

You cannot disable F5 (or other browser shortcut keys) via JavaScript.

Setting the WebBrowserShortcutsEnabled property of the WebBrowser control to false should accomplish what you're trying to do.

josh3736
This works! Thanks!
john
Got a problem. It disables keyboard shortcuts but also disables links that will open IE.
john
Handle the `WebBrowser.Navigating` event: `private void WebBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e) { if (e.Url.ToString() != "about:blank") { System.Diagnostics.Process.Start(e.Url.ToString()); e.Cancel=true; } }`
josh3736
Windows acts weird. Tried pressing F5 continuously then clicking a link but it will not respond to it. But, if you say you put MessageBox onClick event, it will respond to it.
john
A: 

call this function on the onKeyDown event

 document.onkeydown = function(e) {
      // keycode for F5 function
      if (e.keyCode === 116) {
        return false;
      }
      // keycode for backspace
      if (e.keyCode === 8) {
        // try to cancel the backspace
        return false;
      }
    };

This will prevent from F5 reload and backspace back.

Azhar
This does not work.
josh3736
it should work now...
Azhar
this doesn't work. I tried this by injecting in webbrowser. On normal html this will work.
john