Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

How to disable the F5 key.
I don't want to refresh my webpage.
I have already removed toolbar and menubar from the window.
Kindly guide me on this.

Regards,
AP
Posted

See if below code helps:

JavaScript
document.onkeydown = function() 
{
    switch (event.keyCode) 
    {
        case 116 : //F5 button
            event.returnValue = false;
            event.keyCode = 0;
            return false;
        case 82 : //R button
            if (event.ctrlKey) 
            {
                event.returnValue = false;
                event.keyCode = 0;
                return false;
            }
    }
}


Also have a look at below link:

http://chandradev819.wordpress.com/2010/07/03/how-disable-f5-keyword-using-javascript-in-asp-net/[^]
   
Comments
Prasad_Kulkarni 19-Jun-12 1:53am
   
Good answer, in quick time, +5!
Vani Kulkarni 19-Jun-12 2:01am
   
thanks!
Arunprasath Natarajan 19-Jun-12 2:24am
   
Dear Prasad and Vani,
This works fine. But I am opening a child window which has only url tab.
I have give alert in function, it works but still it refresh the page. kindly guide.
Ubaid ur Rahman IT 19-Jun-12 2:46am
   
Helloo Boss !! where should we write this code....I mean in Which Page.
Arunprasath Natarajan 19-Jun-12 3:39am
   
The page which you want to block
Call this function on the onKeyDown event:
C#
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.
Ref.:Disable F5[^]

Also have look for alternatives:
Can the F5 key be disabled [^]

Here you can find example using javaScript:
Disable browser F5 Key[^]
   
v2
Comments
Arunprasath Natarajan 19-Jun-12 2:24am
   
Dear Prasad,
This works fine. But I am opening a child window which has only url tab.
I have give alert in function, it works but still it refresh the page. kindly guide.
Sandeep Singh Shekhawat 2-Jul-15 1:59am
   
Did you get answer of it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900