Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    25
    Thanks
    9
    Thanked 0 Times in 0 Posts

    JavaScript function for Refresh button

    hi,
    Is there any javascript function to find out F5(Refresh) button is pressed?

    Any help would be very much appreacited!.

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Code:
        function ProcessKeypress(e)
        {
             
              if (e.keyCode) keycode=e.keyCode;
              else keycode=e.which;
    if(keycode==116)
    {
    return true;
    }
    else
    {
    return false;
    }
        }
    That function would return true if the user hit f5, and false if the user didn't. You would call it in the body tag like: <body onkeypress="ProcessKeypress(event);">

  • Users who have thanked binaryWeapon for this post:

    tspraveena (05-02-2008)

  • #3
    New Coder
    Join Date
    Apr 2008
    Posts
    25
    Thanks
    9
    Thanked 0 Times in 0 Posts
    No this script is not working. please can you check this?
    Please try it once and let me know.

    I can't able to run this script in
    Code:
       <body onkeypress="ProcessKeypress(event);">
    There is framework outside and i have to work in middle of this framewwork,
    Anyway onloading the file i can able to call this script.
    it didnt worked.
    I was given some alert there, it says undefined for the value of keycode.
    any idea?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I believe you need to check the existence of event object(in some browser) within the function like
    Code:
    if(!e)
     e=window.event;
    // then rest of code
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,915
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Surely most people simply click on the refresh icon.


  •  

    Posting Permissions

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