Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
864 views
in Technique[技术] by (71.8m points)

jquery - JavaScript - How can i tell Browser Chrome, Firefox, Safari, to allow me to have the refresh button disabled?

I have logical application running where i need to store the var algorithmToApply=1 or etc;

Where each of my value has relative algorithm assigned. The main problem is while testing people clicking on browser refresh button and all my application logic crash.

algorithmToApply = 1 ; // Thinking
algorithmToApply = 2 ; // Waiting
algorithmToApply = 11 ; // Downloading
algorithmToApply = 100 ; // Booting
algorithmToApply = 900 ; // Kernel prepare
algorithmToApply = 0 ; // User refresh button is a BUG

How can i using JavaScript request Browsers (Opera or Chrome optionally Firefox/Safari), to allow me to restrict user not able to click refresh (however they can always shutdown or close my browser instance).

Is this possible? If so how?

Follow up: (best we can do )

/* @WARNING: Do not refresh */
$(window).bind('beforeunload', function(e) {  
  if (mystatus>=2) {
   return "WARNING: Your status is .... If you refresh now, software will lose all the status.";
  } else {
   return "WARNING: Your status is not ... You can refresh.";
  }      
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

That is not possible.

You can, however, add a beforeunload listener which prompts for confirmation:

var algorithmToApply = 0;
window.onbeforeunload = function() {
    if (algorithmToApply !== 0) { /* Anything ..*/
        return 'A task is pending. Do you really want to leave?';
    }
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...