Update. A recent comment claims that this does not work in the new Chrome ... As shown in jsFiddle and tested on my personal site, this method still works with Chrome ver 26.0.1410.64 m
In jQuery, this is REALLY REALLY:
// slight update to account for browsers not supporting e.which function disableF5(e) { if ((e.which || e.keyCode) == 116) e.preventDefault(); }; // To disable f5 /* jQuery < 1.7 */ $(document).bind("keydown", disableF5); /* OR jQuery >= 1.7 */ $(document).on("keydown", disableF5); // To re-enable f5 /* jQuery < 1.7 */ $(document).unbind("keydown", disableF5); /* OR jQuery >= 1.7 */ $(document).off("keydown", disableF5);
On the side of the note: This disables only the f5 button on the keyboard. To truly disable the update, you must use the server side of the script to check for page state changes. I canβt say that I really know how to do this, since I have not done it yet.
On the software site I work for, we use my disableF5 function in conjunction with Codeigniter session data. For example, there is a lock button that locks the screen and opens a dialog with a password. The disableF5 function is quick and easy, and this button does nothing. However, to prevent a mouse click on the refresh button, a couple of things happen.
- When you click on a lock, user session data has a variable called "locked" that becomes TRUE
- When you click the refresh button on the loading method of the main page, a check is performed against the session data for βblockedβ, if TRUE, then we simply do not allow redirection and the page never changes, regardless of the requested destination
TIP: Try using a cookie on the server, such as PHP $_SESSION or even .Net Response.Cookies , to support "where" your client is on your site. This is more of a vanilla way to do what I do with the CI session class. The big difference is that CI uses a table in your database, while these vanilla methods store an editable cookie in the client. However, the disadvantage is that the user can clear his cookies.
SpYk3HH Nov 03 2018-11-11T00: 00Z
source share