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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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 mThis is REALLY easy in jQuery by the way:
jsFiddle
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.
TIP: Try using a server-set cookie, such as PHP’s
$_SESSION, or even .Net’sResponse.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.