Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Suppress F5 key

Reply
Thread Tools

Suppress F5 key

 
 
Andrew Poulos
Guest
Posts: n/a
 
      03-29-2005
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
 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      03-29-2005
Andrew Poulos wrote:
> 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.


 
Reply With Quote
 
 
 
 
Andrew Poulos
Guest
Posts: n/a
 
      03-29-2005
Richard Cornford wrote:
> Andrew Poulos wrote:
>
>>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.


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
 
Reply With Quote
 
Zifud
Guest
Posts: n/a
 
      03-31-2005
Andrew Poulos wrote:
> Richard Cornford wrote:
>
>>Andrew Poulos wrote:
>>
>>
>>>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.

>
>
> 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?


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).

>
>>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.
>


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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you disable or suppress the '?' interactive help function John Chajecki Cisco 2 12-17-2005 03:32 PM
How to suppress headers when forwarding with TB David G. Imber Firefox 3 10-17-2005 08:51 PM
Suppress more/pause during running config Marv Cisco 3 06-20-2005 05:33 PM
Replace Tab Key to Return Key (Enter Key) from Web Forms? M P ASP General 1 08-06-2004 08:32 AM



Advertisments