Suppress F5 key

Discussion in 'Javascript' started by Andrew Poulos, Mar 29, 2005.

  1. 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
     
    Andrew Poulos, Mar 29, 2005
    #1
    1. Advertising

  2. 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.
     
    Richard Cornford, Mar 29, 2005
    #2
    1. Advertising

  3. 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
     
    Andrew Poulos, Mar 29, 2005
    #3
  4. Andrew Poulos

    Zifud Guest

    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.
     
    Zifud, Mar 31, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. peshrad
    Replies:
    3
    Views:
    1,509
    David Freeman
    Nov 8, 2004
  2. =?Utf-8?B?SmFzb24gUGV0dHlz?=

    Suppress viewstate __viewstate rendering

    =?Utf-8?B?SmFzb24gUGV0dHlz?=, Jan 14, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    2,919
    Steven Cheng[MSFT]
    Jan 18, 2005
  3. RJN
    Replies:
    1
    Views:
    5,682
    jongalloway
    Mar 5, 2005
  4. =?Utf-8?B?VGltIFN0YWxs?=

    RE: Suppress postback added to history WITHOUT smartnavigation

    =?Utf-8?B?VGltIFN0YWxs?=, Mar 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    694
    =?Utf-8?B?VGltIFN0YWxs?=
    Mar 8, 2005
  5. M P
    Replies:
    1
    Views:
    478
Loading...

Share This Page