Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:47:34+00:00 2026-05-26T14:47:34+00:00

I want to disable browser refreshing using JavaScript. Currently, I am using window.onbeforeunload and

  • 0

I want to disable browser refreshing using JavaScript.

Currently, I am using window.onbeforeunload and I don’t want it to be called when user refreshes the browser.

What is the best way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:47:35+00:00Added an answer on May 26, 2026 at 2:47 pm

    Update A recent comment claims this doesn’t work in the new Chrome … As shown in jsFiddle, and tested on my personal site, this method still works as of Chrome ver 26.0.1410.64 m

    This is REALLY easy in jQuery by the way:

    jsFiddle

    // slight update to account for browsers not supporting e.which
    function disableF5(e) { if ((e.which || e.keyCode) == 116) e.preventDefault(); };
    // To disable f5
        /* jQuery < 1.7 */
    $(document).bind("keydown", disableF5);
    /* OR jQuery >= 1.7 */
    $(document).on("keydown", disableF5);
    
    // To re-enable f5
        /* jQuery < 1.7 */
    $(document).unbind("keydown", disableF5);
    /* OR jQuery >= 1.7 */
    $(document).off("keydown", disableF5);
    

    On a side note:
    This only disables the f5 button on the keyboard.
    To truly disable refresh you must use a server side script to check for page state changes.
    Can’t say I really know how to do this as I haven’t done it yet.

    On the software site that I work at, we use my disableF5 function in conjunction with Codeigniter’s session data. For instance, there is a lock button which will lock the screen and prompt a password dialog. The function “disableF5” is quick and easy and keeps that button from doing anything. However, to prevent the mouse-click on refresh button, a couple things take place.

    1. When lock is clicked, user session data has a variable called “locked” that becomes TRUE
    2. When the refresh button is clicked, on the master page load method is a check against session data for “locked”, if TRUE, then we simple don’t allow the redirect and the page never changes, regardless of requested destination

    TIP: Try using a server-set cookie, such as PHP’s $_SESSION, or even .Net’s Response.Cookies, to maintain “where” your client is in your site. This is the more Vanilla way to do what I do with CI’s Session class. The big difference being that CI uses a Table in your DB, whereas these vanilla methods store an editable cookie in the client. The downside though, is a user can clear its cookies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using window.showmodeldialog for opening a new firefox browser window, i want to
I'm building an autosuggest search, like apple's spotlight... and want to disable the browser
I want to disable Javascript once a page has already loaded. Why? Because I
I want to disable the default contextMenu when a user right-clicks on an input
I want to get the javascript status of any browser. How do i get
I don't want the browser to cache a specified jsp, so I used the
I failed to find a way to disable the browser detection feature added by
I want to open a popup window and disable the parent window. Below is
Duplicate of Disable browser save password functionality Is there a way to tell the
How to check if the user disabled javascript in his browser? For example: the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.