Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 18-Jun-12 19:39pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

See if below code helps:
 
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/[^]
  Permalink  
Comments
Prasad_Kulkarni at 19-Jun-12 1:53am
   
Good answer, in quick time, +5!
Vani Kulkarni at 19-Jun-12 2:01am
   
thanks!
Arunprasath Natarajan at 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 at 19-Jun-12 2:46am
   
Helloo Boss !! where should we write this code....I mean in Which Page.
Arunprasath Natarajan at 19-Jun-12 3:39am
   
The page which you want to block
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
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[^]
  Permalink  
v2
Comments
Arunprasath Natarajan at 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.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,745
1 OriginalGriff 6,696
2 CPallini 5,315
3 George Jonsson 3,599
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 19 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100