SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: prevent refresh

  1. #1
    SitePoint Zealot Paul_M's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    prevent refresh

    dunno if this is the right forum but what the hey...

    does anyone know of a way to prevent the user refreshing a page?

    cheers

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <script type="text/javascript"

      function 
    getKeycode(e)
      {
        
    alert(event.keyCode)
      }

    document.onkeydown getKeycode
    </script>
     
    if you hit f5 the keycode returned is 116 so just do something like

    this

    PHP Code:
    <script type="text/javascript"

      function 
    getKeycode(e)
      {
        if (
    event.keyCode ==116) return false;
      }

    document.onkeydown getKeycode
    </script>
     

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    btw i recommend against doing this, as it will cause aggrevation to users by doing this.

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Andrew:

    The majority of users DON'T refresh using f5 - they use the button above.

    I'd suggest something around the onbeforeUnload event.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx flawless for picking up on that, you must of noticed i'm still half asleep.

  6. #6
    SitePoint Zealot Paul_M's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Flawless_koder


    I'd suggest something around the onbeforeUnload event.

    Flawless
    onbeforeUnload... just looked it up.
    i don't see how that can prevent a refresh.... it just warns people when they're about to close their browsers (isn't it?)
    Also it only works in IE.
    About blocking the F5... i agree with Flawless most people use the big refresh button in the toolbar.

    Basically i want to prevent some form data that t being sent from the previous page from being sent again.
    any suggestions?
    cheers

  7. #7
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i would use sessions and when the user submits something, just check whether the session is registered etc, and use an if statement to do one thing or the other. What server sie language are you using if you have one available?

  8. #8
    SitePoint Zealot Paul_M's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Andrew,

    I am using php as my serverside language.... but the page i want to stop being refreshed is already in a "members-only" section which uses sessions...
    The session is registered when the user logs in...
    i didn't think having a session running would prevent you from refreshing?? (i could be wrong tho)

    cheers


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •