Hook F5

by Svelmoe 11. August 2007 17:25

Removes functionality of F5 (refresh) on a an entire page. Useful with forms etc.

You can remove pretty much any keycode you so choose, but be careful. Users of a website aren't acustomed to having functionality changed/removed, so weigh the benefits with possible consequences.

//Yes. You did read right, no function.
if (document.all)
{
  //for IE browser
  document.onkeydown = function ()
  {
    if (event.keyCode == 116)
    {
      event.keyCode=0;
      return false;
    }
    return event.keyCode;
  }
}
else
{   //for FireFox/Netscape (others?)
  document.onkeypress = function (evt)
  {
    if(evt.keyCode == 116)
    { return false; }
    return evt.keyCode;
  }
}

About Svelmoe

My real name is Allan Svelmøe Hansen.

I live in Denmark, where I work as a developer for hedal:kruse:brohus using SQL Server and the .NET framework since 2004. Svelmoe.dk is a place for my every day thoughts and reactions and the occasional technical blog entry.

I also blog about SQL and MS SQL Server at www.execsql.com so in case you are looking for more about that, please visit that website.



View Allan Svelmøe Hansen's profile on LinkedIn     

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 Svelmoe.dk