Suppress F5 key

A

Andrew Poulos

I'm working on an app where the refreshing of the window by pressing the
F5 key needs to be suppressed. I thought it would be straightforward but
I can't get it to work. This is the code I'm currently trying:

okdh = function(e) {
if (e.which == 116) e.preventDefault();
}
document.addEventListener("keydown", okdh, false);


e.which returns a number
e.which returns 116 when the F5 key is pressed
e.cancelable is true when the F5 key is pressed

Is the default action of the F5 key something that can be suppressed?


Andrew Poulos
 
R

Richard Cornford

Andrew said:
I'm working on an app where the refreshing of the window
by pressing the F5 key needs to be suppressed.
<snip>

Then you have a back-end problem. With an HTTP application the user can
always (so at some point probably will) refresh the currently displayed
page. So you write the back-end so that when this happens there are no
disastrous consequences.

F5 is not the only way of getting a browser to refresh the current page
so preventing its use will not address problems caused by inadequate
back-end code. (There are people who assert that making a problem less
noticeable is equivalent to solving it, but that is not an attitude that
should be promoted)

Now if you wanted to suppress the normal F5 default in order to provide
alternative functionality from that key (and preferably in an Intranet
or non-public web application context) then that could probably be
arranged (especially given a limited range of browsers), but if the
problem is refreshing (and its possible consequences) then messing
around with client-side code is effort expended in the wrong direction.

Richard.
 
A

Andrew Poulos

Richard said:
<snip>

Then you have a back-end problem. With an HTTP application the user can
always (so at some point probably will) refresh the currently displayed
page. So you write the back-end so that when this happens there are no
disastrous consequences.

I don't really understand what you mean. Currently I'm testing locally
with FF 1.01 so I don't have a back-end to have a problem with (I think).
F5 is not the only way of getting a browser to refresh the current page
so preventing its use will not address problems caused by inadequate
back-end code. (There are people who assert that making a problem less
noticeable is equivalent to solving it, but that is not an attitude that
should be promoted)

What happens with frame-based projects where code is initialised in the
frameset and then updated for each displayed frame? Is there really a
way for a refresh not to re-initialise all the code?
Now if you wanted to suppress the normal F5 default in order to provide
alternative functionality from that key (and preferably in an Intranet
or non-public web application context) then that could probably be
arranged (especially given a limited range of browsers), but if the
problem is refreshing (and its possible consequences) then messing
around with client-side code is effort expended in the wrong direction.

The users click, as part of the web app, other Fkeys so the problem is
not preventing a user from refreshing the window but to prevent them
from inadvertently doing so.

Andrew Poulos
 
Z

Zifud

Andrew said:
I don't really understand what you mean. Currently I'm testing locally
with FF 1.01 so I don't have a back-end to have a problem with (I think).




What happens with frame-based projects where code is initialised in the
frameset and then updated for each displayed frame? Is there really a
way for a refresh not to re-initialise all the code?

I guess you'll have to retain state somehow. You can't stop the page
reloading on F5 - you can intercept the event onkeydown but you can't
stop it.

You may need to store values in the URL or a cookie as you go, then
on page load re-initialise the page to its previous state (untested).
The users click, as part of the web app, other Fkeys so the problem is
not preventing a user from refreshing the window but to prevent them
from inadvertently doing so.

Since you can't, you can provide an elegant refresh or expect users
to get annoyed on accidental refresh - who's gonna give way? :)


--
Zif

Inquisitor: Tonto, what would you do if you saw two trains heading
toward each other on the same track at high speed?

Tonto: Call Lone Ranger!

Inquisitor: What would the Lone Ranger do?

Tonto: Nothing, but he love to see train smash.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top